Gridview的一些问题
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="fldPartnerID" ForeColor="Black" GridLines="Vertical"><FooterStyle BackColor="#CCCC99" />
<Columns>
<asp:BoundField DataField="fldPartnerID" HeaderText="编号" ReadOnly="True" SortExpression="fldPartnerID" >
<HeaderStyle Width="80px" />
</asp:BoundField>
<asp:TemplateField HeaderText="用户名" SortExpression="fldPartnerName">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("fldPartnerName") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="100px" />
</asp:TemplateField>
<asp:BoundField DataField="fldOrgName" HeaderText="公司名称" SortExpression="fldOrgName" >
<HeaderStyle Width="170px" />
</asp:BoundField>
<asp:TemplateField HeaderText="代理商类型" SortExpression="fldType">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# TypeChange(Eval("fldType")) %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="140px" />
</asp:TemplateField>
<asp:BoundField DataField="fldContactName" HeaderText="联系人" SortExpression="fldContactName" >
<HeaderStyle Width="120px" />
</asp:BoundField>
<asp:BoundField DataField="fldRegDate" HeaderText="注册时间" SortExpression="fldRegDate" >
<HeaderStyle Width="190px" />
</asp:BoundField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="BtDis" runat="server" Text="禁用" CommandName="isDiss" />
<asp:Button ID="BtDetail" runat="server" Text="详细" CommandName="Detail />
</ItemTemplate>
<HeaderStyle Width="140px" />
</asp:TemplateField>
</Columns>
如果我想单击一下"禁用" 按钮上的文字就变成"启用"
这个功能应该怎么实现? --------------------编程问答-------------------- LZ 看看这个
http://blog.csdn.net/liyin_liu/archive/2008/05/08/2415145.aspx --------------------编程问答-------------------- 禁用和启用在数据库中要设一个字段用int 或bit 或true false表示都行
然后绑定的时候判断一下就行了.下面有个例子
--------------------编程问答-------------------- if( ((Button)this.GridView1.Rows[i].Cells[10].FindControl("BtDis")).Text = "禁止")
count = this.GridView1.Rows.Count;
for (int i = 0; i < count; i++)
{
if (ds.Tables[0].Rows[i]["字段名"].ToString().Equals("1"))
{
((Button)this.GridView1.Rows[i].Cells[10].FindControl("按钮名")).Text = "禁止";
}
else
{
((Button)this.GridView1.Rows[i].Cells[10].FindControl("按钮名")).Text = "启用";
}
}
{
((Button)this.GridView1.Rows[i].Cells[10].FindControl("BtDis")).Text = "启用")
} --------------------编程问答-------------------- 谁有VB code写法吗??
--------------------编程问答--------------------
<asp:GridView ID="GridView1" ... OnRowCommand="GridView1_RowCommand">
...
</asp:GridView>
--------------------编程问答-------------------- 还有
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "isDiss")
{
Button btn = (Button)e.CommandSource;
btn.Text = (btn.Text == "禁用" ? "启用" : "禁用");
}
}
<asp:Button ID="BtDetail" runat="server" Text="详细" CommandName="Detail />
=======
应为
<asp:Button ID="BtDetail" runat="server" Text="详细" CommandName="Detail" />
最后少了双引号
VB.NET的写法和 C#很接近,不用再给了吧..
补充:.NET技术 , ASP.NET