My gridview is bound to List when users click a refresh button as follows:
grv_xyz.DataSource = lstVendorInfo;
grv_zyz.DataBind();
I put a <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />
before all other TemplateFields to display data like
<Columns>
<asp:CommandField HeaderText="Delet开发者_如何学JAVAe" ShowDeleteButton="True" ShowHeader="True" />
<asp:TemplateField HeaderText="Vendor ID">
<ItemStyle Width="10%" BorderColor="#efefef" BorderWidth="1px"/>
<ItemTemplate>
<asp:HyperLink NavigateUrl="#" ID="abcID" runat="server" Text='<%# Bind("abc") %>'></asp:HyperLink>
</ItemTemplate>
<HeaderStyle BorderColor="#efefef" />
</asp:TemplateField>
</Columns>
The problem is cell. Text property in the following is ""
.
protected void grv_Vendor_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
ShowResult();
TableCell cell = grv_Vendor.Rows[e.RowIndex].Cells[4];
}
How could I retieve the value inside a TemplateField in RowDeleting event?
Thanks a lot.
A TemplateField includes controls, so the value should be accessed through them. For example, if you have a label inside a TemplateField and you want to access its value, you would write:
Label yourLabel = e.Item.FindControl("YourLabelID") as Label;
string val = yourLabel.Text;
精彩评论