如何在后台C#给BoundField赋值属性
1个回答
展开全部
前台一个GridView控件:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="257px" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="ID" ReadOnly="true" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="姓名" />
<asp:BoundField DataField="username" HeaderText="昵称" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" CommandName ="del" CommandArgument ='<%#Eval("ID") %>' runat="server">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台:
protected void Page_Load(object sender, EventArgs e)
{
string sql = "select * from PostLog";
DataTable data = common.common.GetListCeshi(sql, 0, 0);
GridView1.DataSource = data;
GridView1.DataBind();
DateTime da = DateTime.Now;
Response.Write(da.ToShortDateString().ToString());
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName=="del")
{
Response.Write(e.CommandArgument);//得到绑定的ID值
}
}
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Width="257px" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:BoundField DataField="ID" ReadOnly="true" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="姓名" />
<asp:BoundField DataField="username" HeaderText="昵称" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" CommandName ="del" CommandArgument ='<%#Eval("ID") %>' runat="server">删除</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台:
protected void Page_Load(object sender, EventArgs e)
{
string sql = "select * from PostLog";
DataTable data = common.common.GetListCeshi(sql, 0, 0);
GridView1.DataSource = data;
GridView1.DataBind();
DateTime da = DateTime.Now;
Response.Write(da.ToShortDateString().ToString());
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName=="del")
{
Response.Write(e.CommandArgument);//得到绑定的ID值
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询