asp.net中GridView的问题,如果某一列BoundField被设置为readonly,在后台中如和获取到它的单元格中的值
展开全部
如果是后台通过数据库查询绑定的GridView,readonly是没有影响。
如下面的小例子:
前台一个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值
}
}
如下面的小例子:
前台一个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值
}
}
展开全部
前台一个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值
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
如果是使用的ItemCommond的话,可以使用e.SelectIndex.BoundField绑定列ID.text来获取
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
实现方法:
循环GridView,找到这一行中对应列的数据
不懂@我
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
GridView1.Rows[0].Cells[0].Text
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询