我有一个网格视图,其中的边界是这样的东西-
<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";
}
}但它并没有给我展示我想要显示的所需的文本。有人能给我建议可能的解决办法吗?
发布于 2013-09-07 04:40:37
不要使用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";
}
}https://stackoverflow.com/questions/18669703
复制相似问题