外部的button如何获取gridview行的索引
<div><asp:gridviewid="GridView1"runat="server"autogeneratecolumns="False"backcolor="W...
<div>
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" backcolor="White"
bordercolor="#DEDFDE" borderstyle="None" borderwidth="1px" cellpadding="4" forecolor="Black"
gridlines="Vertical" height="54px" onrowediting="GridView1_RowEditing" width="645px" datakeynames="u_name">
<rowstyle backcolor="#F7F7DE" />
<columns>
<asp:boundfield datafield="u_name" headertext="用户名" />
<asp:boundfield datafield="u_tel" headertext="联系方式" />
<asp:boundfield datafield="u_add" headertext="联系地址" />
<asp:boundfield datafield="u_power" headertext="用户权限" />
<asp:commandfield buttontype="Button" headertext="编辑" showeditbutton="True" />
</columns>
<footerstyle backcolor="#CCCC99" />
<pagerstyle backcolor="#F7F7DE" forecolor="Black" horizontalalign="Right" />
<selectedrowstyle backcolor="#CE5D5A" font-bold="True" forecolor="White" />
<headerstyle backcolor="#6B696B" font-bold="True" forecolor="White" />
<alternatingrowstyle backcolor="White" />
</asp:gridview>
<br />
<br />
<br />
<br />
</div>
<asp:panel id="Panel1" runat="server" height="237px" width="463px">
<br />
您选择编辑的用户是:<asp:label id="Label1" runat="server" text="Label"></asp:label><br />
<br />
用户名: <asp:textbox id="tb_name" runat="server"></asp:textbox>
<br />
<br />
联系方式:<asp:textbox id="tb_tel" runat="server"></asp:textbox><br />
<br />
联系地址:<asp:textbox id="tb_add" runat="server"></asp:textbox><br />
<br />
用户权限:<asp:dropdownlist id="ddl_power" runat="server">
<asp:listitem>请选择</asp:listitem>
<asp:listitem value="0">管理员</asp:listitem>
<asp:listitem value="1">普通用户</asp:listitem>
</asp:dropdownlist>
<br />
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click" text="确认修改" /></asp:panel>
protected void Button1_Click(object sender, EventArgs e)
{
string id=this.GridView1.DataKeys["u_id"].Value.ToString();
我就是想知道这个怎么定义。
string name = this.tb_name.Text.ToString();
string tel = this.tb_tel.Text.ToString();
string add = this.tb_add.Text.ToString();
string power = this.ddl_power.SelectedItem.ToString();
string sql = "update users set u_name='" + name + "',u_tel='" + tel + "',u_add='" + add + "',u_power='" + power + "'where id='"+id+"'"; 展开
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" backcolor="White"
bordercolor="#DEDFDE" borderstyle="None" borderwidth="1px" cellpadding="4" forecolor="Black"
gridlines="Vertical" height="54px" onrowediting="GridView1_RowEditing" width="645px" datakeynames="u_name">
<rowstyle backcolor="#F7F7DE" />
<columns>
<asp:boundfield datafield="u_name" headertext="用户名" />
<asp:boundfield datafield="u_tel" headertext="联系方式" />
<asp:boundfield datafield="u_add" headertext="联系地址" />
<asp:boundfield datafield="u_power" headertext="用户权限" />
<asp:commandfield buttontype="Button" headertext="编辑" showeditbutton="True" />
</columns>
<footerstyle backcolor="#CCCC99" />
<pagerstyle backcolor="#F7F7DE" forecolor="Black" horizontalalign="Right" />
<selectedrowstyle backcolor="#CE5D5A" font-bold="True" forecolor="White" />
<headerstyle backcolor="#6B696B" font-bold="True" forecolor="White" />
<alternatingrowstyle backcolor="White" />
</asp:gridview>
<br />
<br />
<br />
<br />
</div>
<asp:panel id="Panel1" runat="server" height="237px" width="463px">
<br />
您选择编辑的用户是:<asp:label id="Label1" runat="server" text="Label"></asp:label><br />
<br />
用户名: <asp:textbox id="tb_name" runat="server"></asp:textbox>
<br />
<br />
联系方式:<asp:textbox id="tb_tel" runat="server"></asp:textbox><br />
<br />
联系地址:<asp:textbox id="tb_add" runat="server"></asp:textbox><br />
<br />
用户权限:<asp:dropdownlist id="ddl_power" runat="server">
<asp:listitem>请选择</asp:listitem>
<asp:listitem value="0">管理员</asp:listitem>
<asp:listitem value="1">普通用户</asp:listitem>
</asp:dropdownlist>
<br />
<br />
<asp:button id="Button1" runat="server" onclick="Button1_Click" text="确认修改" /></asp:panel>
protected void Button1_Click(object sender, EventArgs e)
{
string id=this.GridView1.DataKeys["u_id"].Value.ToString();
我就是想知道这个怎么定义。
string name = this.tb_name.Text.ToString();
string tel = this.tb_tel.Text.ToString();
string add = this.tb_add.Text.ToString();
string power = this.ddl_power.SelectedItem.ToString();
string sql = "update users set u_name='" + name + "',u_tel='" + tel + "',u_add='" + add + "',u_power='" + power + "'where id='"+id+"'"; 展开
1个回答
展开全部
使用gridview 和 linkbutton 传递参数
gridview 添加一列
<asp:TemplateField><ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnCommand="click" CommandArgument='<%#eval_r(" 要选列的ID号")%>'>
随意</asp:LinkButton>
</ItemTemplate></asp:TemplateField>
在 .CS 文件中:
protected void click(object sender, CommandEventArgs e)
{
// 如此获取参数
int id = int.Parse((string)e.CommandArgument);
string cid = id.ToString().Trim();
}
gridview 添加一列
<asp:TemplateField><ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" OnCommand="click" CommandArgument='<%#eval_r(" 要选列的ID号")%>'>
随意</asp:LinkButton>
</ItemTemplate></asp:TemplateField>
在 .CS 文件中:
protected void click(object sender, CommandEventArgs e)
{
// 如此获取参数
int id = int.Parse((string)e.CommandArgument);
string cid = id.ToString().Trim();
}
追问
我的gridview已经用了编辑按钮了,
用这个可以么
追答
以前我没用过,button 好像都是用 linkButton ,我查了很多资料,就搜到LinkButton
我也是刚开始学asp.net 的
助教教的,网上找到的,好像都是 linKbutton
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询