[英]Gridview RowCommand event
我有一个gridview,其中boundfield是这样的-
<asp:BoundField HeaderText="Approved" />
在此gridview的rowcommand事件上,我想根据命令名称显示一些文本,例如
protected void gwFacultyStaff_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Yes"))
{
string id = e.CommandArgument.ToString();
GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
int index = Convert.ToInt32(row.RowIndex);
GridViewRow rows = gwFacultyStaff.Rows[index];
rows.Cells[12].Text = "TRUE";
}
else if (e.CommandName.Equals("No"))
{
string id = e.CommandArgument.ToString();
GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
int index = Convert.ToInt32(row.RowIndex);
GridViewRow rows = gwFacultyStaff.Rows[index];
rows.Cells[12].Text = "FALSE";
}
}
但是它没有显示我想要显示的必需文本。 有人可以建议我解决方案吗?
代替BoundField
使用TemplateField
,如下所示:
<asp:TemplateField HeaderText="Approved">
<ItemTemplate>
<asp:Label id="LabelApproved" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
现在,在您的RowCommand
事件中,您可以执行以下操作:
protected void gwFacultyStaff_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Yes"))
{
GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
Label theLabel = row.FindControl("LabelApproved") as Label;
theLabel.Text = "TRUE";
}
else if (e.CommandName.Equals("No"))
{
GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer;
Label theLabel = row.FindControl("LabelApproved") as Label;
theLabel.Text = "FALSE";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.