How to select a cell in datagrid onClick in ASP.net C#

后端 未结 2 452
栀梦
栀梦 2021-01-28 14:31

I am importing a column in datatable to my grid. Now I want navigate to a new page on selecting a cell in grid by fetching the selected value. I have tried this by including bou

相关标签:
2条回答
  • 2021-01-28 14:53

    In your case you are binding boundfield with static a tag which have href attribute so your not able to change text on that boundfield from your database.To get your approach you should use TemplateField and bind data with text attribute using eval keyword as below example.

    Try it:

    <asp:TemplateField HeaderText="Name">
        <ItemTemplate>
            <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("name") %>' />
        </ItemTemplate>
    </asp:TemplateField>
    

    OR

    you can also bind link with your hyperlink using NavigateUrl property of hyperlink as below example.

    <asp:TemplateField HeaderText="Name">
          <ItemTemplate>
              <asp:HyperLink id="HyperLink2" NavigateUrl='<%#Eval("YourUrl") %>' Text='<%#Eval("name") %>' runat="server"/>
          </ItemTemplate>
    </asp:TemplateField>
    

    I hope it will helpful to you.

    0 讨论(0)
  • 2021-01-28 15:10

    You can use TemplateField

    <asp:TemplateField HeaderText="Name">
            <ItemTemplate>
                <asp:LinkButton runat="server" ID="lnk<%# Eval("SRONameinEnglish")%>"><%# Eval("SRONameinEnglish")%></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    

    and click of LinkButton put your code to navigate anywhere.

    0 讨论(0)
提交回复
热议问题