如何选择数据网格的onClick在ASP.net C#中的单元格 [英] How to select a cell in datagrid onClick in ASP.net C#

查看:78
本文介绍了如何选择数据网格的onClick在ASP.net C#中的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导入数据表列到我的网格。现在我想转到一个新的页面上获取所选择的值选择在网格中的单元格。我已经包括绑定字段在我的网格试过这种像

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 bound field in my grid like

 <asp:GridView ID="GDV_1" runat="server" EnableModelValidation="true" AutoGenerateColumns="false" OnSelectedIndexChanged="GDV_1_SelectedIndexChanged" AutoGenerateSelectButton="false" DataKeyNames="SROID">
      <Columns>
         <asp:BoundField DataField="SRONameinEnglish" HtmlEncode="False" DataFormatString="<a target='_blank' href='Test.aspx?code={0}>ClickHere</a>" />
      </Columns>
 </asp:GridView>

做这样我的要求是实现,但所有的细胞显示常用的文本点击显示从数据库中的数据在这里来代替。

请给你的关于如何从数据库到单元格的值的建议,并使其点击。我不想使用选择按钮。请找我的电流输出。
这是从 DB 而不是 ClickHere

Please give your suggestion on how to get the value from database into cell and make it clickable. I don't want to use Select button. Please find my current output. This is my current output I want my data from DB instead of ClickHere.

推荐答案

在你的情况你要绑定的BoundField 静态标记具有的href 属性让你无法改变文本的BoundField 获得你的方法,你应该
通过使用模板列和数据绑定文本属性评估关键字如下面的例子。

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.

试试吧:

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

您也可以绑定链接使用超链接 NavigateUrl 属性作为下面的例子超链接。

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.

这篇关于如何选择数据网格的onClick在ASP.net C#中的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆