在datagridview中隐藏列,但要使用此列中的值 [英] Hide column in datagridview but want to use value from this column
本文介绍了在datagridview中隐藏列,但要使用此列中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我在datagridview中显示了名为id,data1,data2的3列.现在我有一个问题要ID列,然后在gridview中有1个链接按钮.
当我当时在"rowdeleting"事件中单击该按钮时,我想要该行的id值.
请帮助我.
预先感谢.
Hello,
I have display 3 column in datagridview named id,data1,data2. Now I have problem that i want to id column and then there is 1 link button in gridview.
When I click on that button at that time in "rowdeleting" event i want value of id from that row.
Kindly help me.
Thanks in advance.
推荐答案
以下代码片段将隐藏与gridview列关联的值.
The following code snippet will to hide the value associated with gridview column.
<asp:GridView ID="gvData" runat="server"
AutoGenerateColumns="False" EmptyDataText="There are no data records to display."
CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" Height="272px" Style="font-family: Consolas">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField HeaderText="Data 1">
<ItemTemplate>
<asp:Label ID="lblId" runat="server" Text='<%# Bind("id") %>' Visible="false"></asp:Label>
<asp:Label ID="lblData1" runat="server" Text='<%# Bind("data1") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Data 2">
<ItemTemplate>
<asp:Label ID="lblData2" runat="server" Text='<%# Bind("data2") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
id列与不可见的标签关联.因此,您可以访问与此标签绑定的数据.
The id column is associated with non visible label. So you can access the data that is binded with this label.
使用此代码
Use this code
<asp:GridView ID="GridView1" runat="server" CssClass="GridViewStyle"
DataKeyNames="id" AutoGenerateColumns="False" OnRowDeleting="DeleteRecord"
AllowPaging="True" AllowSorting="true" PageSize="15"
OnPageIndexChanging="ChangePage" OnSorting="SortRecords">
<Columns>
<asp:BoundField DataField="id" HeaderText="S No" ReadOnly="True" SortExpression="id" Visible="false" />
只需将其宽度设置为0%.
希望对您有所帮助.
Just give its width to 0%.
Hope this can help you.
这篇关于在datagridview中隐藏列,但要使用此列中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文