请教GIRDVIEW控件的问题 急!!! 请问我想在GirdView 中的第5列加一列Button控件 实现单击某一行的Button控件 可以更新本行第1列的文字内容 请问这行第1列的内容 怎么用语句表示?如(string A = 这行第1列的内容 )这种形式。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 i是行索引string A=GridView1.Rows[i].Cells[0].Text; <asp:TemplateField HeaderText="点击"> <ItemTemplate> <asp:Button ID="ButtonClick" runat="server" CommandArgument='<%# Eval("id") %>' CommandName="ClickButton" /> </ItemTemplate></asp:TemplateField>// id 是当前行的标识 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (null != e.CommandName) { string cmd = e.CommandName; int id = 0; if (null != e.CommandArgument) { id = Convert.ToInt32(e.CommandArgument); if ("ClickButton".Equals(cmd)) { // 在这里面修改当前行第一列的值 } } }} 动态生成 ButtonFieldButtonField buttonF1 = new ButtonField();buttonF1.CommandName = "btn_Edit";buttonF1.Text = "编辑";buttonF1.HeaderText = "编辑";buttonF1.ButtonType = ButtonType.Button;GridView1.Columns.Add(buttonF1);然后 GridView1_RowCommand 事件就是按钮的事件了。这里你可以取得行号 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("btn_Delete")) { //....... } if (e.CommandName.Equals("btn_Edit")) { //....... int rowNum = GridView1.PageIndex * GridView1.PageSize + Convert.ToInt32(e.CommandArgument); //Convert.ToInt32(e.CommandArgument)就是行号,这里是因为GridView1有分页,//没有直接取就行 } }有了行号,GridView1 就随你蹂躏了 GridView1.Rows[e.row].Cells[0].Text; e.你点一下就能看到,操作的是当前行 i 就是索引 e.Rowindex不用那个也行 直接在你的button里直接绑定 那一行的ID<asp:LinkButton ID="lkb_delete" CommandName="Delete" CommandArgument= ' <%#Eval( "id ") Text="删除" %> '/> Gridview中的deleting事件在后台获取的时候 protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { int id = Convert.ToInt32((this.GridView1.Rows[e.RowIndex].FindControl("lkb_delete") as LinkButton).CommandArgument);} <asp:LinkButton ID="lbtnUpdate" runat="server" CommandArgument='<%# Container.DataItemIndex %>' CommandName="Update">修改</asp:LinkButton><asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name")%>'></asp:TextBox>//要修改的那列protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e){ if (e.CommandName == "Update") { string txtName = null; txtName = ((TextBox)GridView1.Rows[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("txtName")).Text.Trim();if (){ //修改成功! 重新绑定到GridView}else //修改失败!}} 起始用datalist不是更方便吗?你要的那效果 fckeditor中关于插入表格的问题 关于页面间参数传递的一个问题 ▂▃▄▅弹出页面改变样式▅▄▃▂ TreeView的ImageSet属性的问题? Gridview在后台无法显示在问 项目中数据库的设计问题 求教关于calendar控件 各位高手,问一个简单的问题,怎样在框架页面下,将一个参数从框架面的一边传到另一边?帮帮我吧!谢谢了! 怎样获取应用程序根目录 剛入門,請教一下下! 简单的SQL问题 请教怎么才能从一个图片中截取一部分生成一个新的图片?
string A=GridView1.Rows[i].Cells[0].Text;
<asp:TemplateField HeaderText="点击">
<ItemTemplate>
<asp:Button ID="ButtonClick" runat="server" CommandArgument='<%# Eval("id") %>' CommandName="ClickButton" />
</ItemTemplate>
</asp:TemplateField>// id 是当前行的标识 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (null != e.CommandName)
{
string cmd = e.CommandName;
int id = 0;
if (null != e.CommandArgument)
{
id = Convert.ToInt32(e.CommandArgument);
if ("ClickButton".Equals(cmd))
{
// 在这里面修改当前行第一列的值
}
}
}
}
buttonF1.CommandName = "btn_Edit";
buttonF1.Text = "编辑";
buttonF1.HeaderText = "编辑";
buttonF1.ButtonType = ButtonType.Button;
GridView1.Columns.Add(buttonF1);然后 GridView1_RowCommand 事件就是按钮的事件了。这里你可以取得行号 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("btn_Delete"))
{
//.......
}
if (e.CommandName.Equals("btn_Edit"))
{
//.......
int rowNum = GridView1.PageIndex * GridView1.PageSize + Convert.ToInt32(e.CommandArgument);
//Convert.ToInt32(e.CommandArgument)就是行号,这里是因为GridView1有分页,
//没有直接取就行
}
}
有了行号,GridView1 就随你蹂躏了
<asp:LinkButton ID="lkb_delete" CommandName="Delete" CommandArgument= ' <%#Eval( "id ") Text="删除" %> '/> Gridview中的deleting事件
在后台获取的时候
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{ int id = Convert.ToInt32((this.GridView1.Rows[e.RowIndex].FindControl("lkb_delete") as LinkButton).CommandArgument);
}
<asp:TextBox ID="txtName" runat="server" Text='<%# Eval("Name")%>'></asp:TextBox>//要修改的那列protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Update")
{
string txtName = null;
txtName = ((TextBox)GridView1.Rows[Convert.ToInt32(e.CommandArgument.ToString())].FindControl("txtName")).Text.Trim();
if ()
{
//修改成功!
重新绑定到GridView
}
else
//修改失败!
}
}