gridview 新加按钮 取该行某列值 在gridview里的添加一列,里面放置一个按钮,设定其commandname="insertitems"点击此按钮,转到下一页面希望在转到下一页面的同时,取出该按钮所在行的 列名为 ID的值并保存在Session里面 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void Button1_Click(object sender, EventArgs e) { Button myB = (Button)sender; int myIndex = ((GridViewRow)myB.NamingContainer).RowIndex;//获得行号 int myId = Convert.ToInt16(GridView1.DataKeys[myIndex].Value);//获得id Session["sMyId"]=myId; } 在按钮里绑定commandArgument为ID值,rowcommand里取commandargument即得到ID 为GridView添加模板列:<asp:TemplateField> <ItemTemplate> <asp:Button ID="Button1" runat="server" CommandArgument='<%# Eval("ID") %>' OnClick="Button1_Click" Text="跳转" /> </ItemTemplate></asp:TemplateField>后台:protected void Button1_Click(object sender, EventArgs e){ int id = int.Parse((sender as Button).CommandArgument); Session["id"] = id; Response.Redirect("下一页面");} 把ID主键设为GridView的DataKeys,CommandName="Edit" 或其他GridView里有的事件 Edit的话,点击生成 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){}方法 在里面写代码 int id = int.Parse(GridView1.DataKeys[e.NewEditIndex].Value.ToString());获取当前行ID的值 存到Session里就OK了 IIS的web目录在哪里?怎么找啊?? 是在本机的!! 后台调用script脚本的问题 关于防刷新功能 请教:滚动图片新闻不能传两个参数呢 散分(100)!!! jQuery 得到返回值后,如果把结果更新到页面中去,跪谢! 关于照片批量导入的问题 _______"超时已过期",错误,谢谢 菜鸟! 我是asp.net的初学者,在调试asp.net程序时总是出现下列错误 怎么样把静态页面转化成动态的页面? 360度全景flash如何制作
{
Button myB = (Button)sender;
int myIndex = ((GridViewRow)myB.NamingContainer).RowIndex;//获得行号
int myId = Convert.ToInt16(GridView1.DataKeys[myIndex].Value);//获得id
Session["sMyId"]=myId; }
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CommandArgument='<%# Eval("ID") %>' OnClick="Button1_Click" Text="跳转" />
</ItemTemplate>
</asp:TemplateField>
后台:protected void Button1_Click(object sender, EventArgs e)
{
int id = int.Parse((sender as Button).CommandArgument);
Session["id"] = id;
Response.Redirect("下一页面");
}
Edit的话,点击生成 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e){}方法 在里面写代码
int id = int.Parse(GridView1.DataKeys[e.NewEditIndex].Value.ToString());获取当前行ID的值 存到Session里就OK了