locked
dynamic text gridview RRS feed

  • Question

  • User-264693890 posted

    Hello

    I have databound column, how do I create dynamic text like the example below?

    Text="This is {0:c}" 

    or

    HeaderText="This is {0:c}"

    <asp:HyperLinkField DataNavigateUrlFields="Test" DataNavigateUrlFormatString="https://localhost/{0}" DataTextFormatString="{0:c}" Text="This is {0:c}" HeaderText="This is {0:c}" target="_blank" />

    Thanks

    Friday, May 22, 2020 4:27 PM

All replies

  • User409696431 posted

    Can you clarify?  Dynamic text for what?  There can only be one HeaderText, since there is only one header for the entire column, not a header for each link.

    If you mean the text for the link, set the DataTextField and add the text you want to the DataTextFormatString.

    <asp:HyperLinkField DataNavigateUrlFields="Test" DataNavigateUrlFormatString="https://localhost/{0}" DataTextField="Test" DataTextFormatString="This is {0}" HeaderText="The Header for Test">
    </asp:HyperLinkField>
    

    Saturday, May 23, 2020 12:47 AM
  • User288213138 posted

    Hi evsion1,

    I have databound column, how do I create dynamic text like the example below?

    Text="This is {0:c}" 

    or

    HeaderText="This is {0:c}"

    <asp:HyperLinkField DataNavigateUrlFields="Test" DataNavigateUrlFormatString="https://localhost/{0}" DataTextFormatString="{0:c}" Text="This is {0:c}" HeaderText="This is {0:c}" target="_blank" />

    Do you want to set your Test field to currency form? if yes, then you can try the following code:

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
                    <Columns>
                        <asp:hyperlinkfield datatextfield="Test" DataTextFormatString="{0:c}" DataNavigateUrlFields="Test" DataNavigateUrlFormatString="https://localhost/{0}" headertext="Price" target="_blank" />
                    </Columns>
                </asp:GridView>

    Best regards,

    Sam

    Monday, May 25, 2020 3:09 AM