Tôi có một GridView
quy định như sau:Nhận Hidden Giá trị trường
<asp:GridView ID="myGridView" AutoGenerateColumns="false" runat="server"
OnLoad="myGridView_Load" OnRowCommand="myGridView_Command" OnRowEditing="myGridView_RowEditing" OnRowDeleting="myGridView_RowDeleting" DataKeyNames="ID" >
<Columns>
<asp:BoundField DataField="ID" Visible="false" />
<asp:BoundField DataField="BirthDate" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:TemplateField HeaderText="Other">
<ItemTemplate>
<asp:LinkButton ID="editLB" runat="server" Text="edit" CommandName="Edit" />
<asp:LinkButton ID="deleteLB" runat="server" Text="delete" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Khi người dùng nhấp vào nút chỉnh sửa, tôi cần để có được giá trị của cột BirthDate
. Để thực hiện điều này, tôi đã thử các cách sau:
protected void myGridView_RowEditing(object sender, GridViewEditEventArgs e)
{
GridViewRow row = gvUsers.Rows[e.NewEditIndex];
DateTime birthDate = (DateTime)(row.Cells[1].Text);
// Does not work
}
Tôi biết nó có liên quan đến việc cột không hiển thị. Cột phải được ẩn. Nhưng tôi cần phải nhận được giá trị đó — làm cách nào tôi có thể thực hiện việc này?
tôi đã cố gắng thứ hai nhưng nó hided chỉ các giá trị và tiêu đề vẫn còn tồn tại. làm thế nào tôi có thể ẩn cũng tiêu đề? (Tôi không thể sử dụng hiển thị = false vì tôi neet dữ liệu của nó) – Rapunzo
đặt lớp css tiêu đề để ẩn – MattBH