如何获取隐藏列值 [英] How to get Hidden Column value
本文介绍了如何获取隐藏列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的网格视图
This is my grid view
<asp:GridView ID="grdDepartment" runat="server" BackColor="White"
BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3"
ForeColor="Black" GridLines="Vertical" Width="293px"
AutoGenerateColumns="False" AutoGenerateSelectButton="True"
onselectedindexchanged="grdDepartment_SelectedIndexChanged">
<AlternatingRowStyle BackColor="#CCCCCC" />
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
<Columns>
<asp:BoundField HeaderText ="ID" DataField ="ID" Visible="false" />
<asp:BoundField HeaderText="Department" DataField="Department Name"/>
</Columns>
</asp:GridView>
我无法访问ID col的值以下代码:/ b $ b
and i am unable to access value of ID column by below code
protected void grdDepartment_SelectedIndexChanged(object sender, EventArgs e)
{
lblID.Text = grdDepartment.SelectedRow.Cells[1].Text;
txtDepartment.Text = grdDepartment.SelectedRow.Cells[2].Text;
}
推荐答案
试试这个,
try this,
<asp:BoundField HeaderText ="ID" DataField ="ID" />
删除visible =false并从后面的代码设置visible = false。
remove visible="false" and set visible=false from code behind.
lblID.Text = grdDepartment.SelectedRow.Cells[0].Text;
txtDepartment.Text = grdDepartment.SelectedRow.Cells[1].Text;
grdDepartment.Columns.Item(0).Visible =false;
谢谢
thanks
您需要使用 DataItem 。关注:
You need to use DataItem . Follow:
DataRowView rowView = (DataRowView)e.Row.DataItem;
int id = Convert.ToInt32(rowView["ID"]);
//use id as your need..
还有更多方法可以获得它。阅读CP文章:
如何在GridView中获取隐藏列值 [ ^ ]
这篇关于如何获取隐藏列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文