如何选择一个单元格在datagrid onClick在ASP.net C# [英] How to select a cell in datagrid onClick in ASP.net C#
问题描述
我将datatable中的列导入到我的网格。现在,我想通过获取所选值来导航到选择网格中的单元格的新页面。我已经尝试过在网格中包含绑定字段,如
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>
以这种方式,我的要求是实现的,但所有单元格都显示常用文本点击这里
而不是从数据库显示数据。
Doing this way my requirement is achieved but the all cells are displaying Common text Click here
instead of showing data from Database.
请提供有关如何从数据库中获取值到单元格的建议,并使其可点击
。我不想使用选择按钮
。请查找我当前的输出。
这是我当前的输出我想要我的数据从 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
上的文本。您应该
使用 TemplateField
,并使用 eval关键字
绑定文本属性的数据,如下所示。
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>
OR
您也可以使用超链接的 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>
希望对您有所帮助。
这篇关于如何选择一个单元格在datagrid onClick在ASP.net C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!