C# 基于单元格值C更改asp:gridview中的按钮文本#
我正在尝试将单元格值从gridview传递给我的代码隐藏。最后,我需要根据单元格值更改按钮的文本 以下是我的代码: My.aspx页面:C# 基于单元格值C更改asp:gridview中的按钮文本#,c#,asp.net,C#,Asp.net,我正在尝试将单元格值从gridview传递给我的代码隐藏。最后,我需要根据单元格值更改按钮的文本 以下是我的代码: My.aspx页面: <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <asp:GridView ID="gridView1" runat="server" OnRowCommand="gview_RowCommand" AutoGenerateCol
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:GridView ID="gridView1" runat="server" OnRowCommand="gview_RowCommand" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Active Status">
<ItemTemplate>
<asp:Label ID="Active" runat="server" Text='<%# Eval("IsActive") %>'></asp:Label>
<asp:Button runat="server" ID="buttonChangeActiveStatus" CommandName="<%# Eval("IsActive") %>" CommandArgument="<%# Eval("IsActive") %>" onclick="buttonChangeActiveStatus_Click" text=""/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
和my.cs代码隐藏:
protected void gview_RowCommand(Object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gridView1.Rows.Count - 1; i++)
{
Button activeButton = (Button)gridView1.Rows[i].FindControl("buttonChangeActiveStatus");
// if (cellValue = true)
// {
//change button text foo
// }
// else
// {
// //change button text to bar
// }
}
}
受保护的void gview_row命令(对象发送方,GridViewRowEventArgs e)
{
对于(int i=0;i
受保护的void gview_RowDataBound(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
Button btnnew=(Button)e.Row.FindControl(“buttonChangeActiveStatus”);
Label lblactive=(Label)e.Row.FindControl(“活动”);
btnnew.Text=Label.Text;
}
}
找到了答案。以下是我添加到代码背后的内容:
protected void RowDataBound(Object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gridView.Rows.Count - 1; i++)
{
Button activeButton = (Button)gridViewTenantDetails.Rows[i].FindControl("buttonChangeActiveStatus");
string cellValue = activeButton.CommandArgument.ToString();
if (cellValue == "True")
{
activeButton.Text = "foo";
}
else
{
activeButton.Text = "bar";
}
}
}
受保护的void行数据绑定(对象发送方,GridViewRowEventArgs e)
{
对于(int i=0;i
protected void RowDataBound(Object sender, GridViewRowEventArgs e)
{
for (int i = 0; i <= gridView.Rows.Count - 1; i++)
{
Button activeButton = (Button)gridViewTenantDetails.Rows[i].FindControl("buttonChangeActiveStatus");
string cellValue = activeButton.CommandArgument.ToString();
if (cellValue == "True")
{
activeButton.Text = "foo";
}
else
{
activeButton.Text = "bar";
}
}
}