asp.net C# 中在Gridview中的ItemTemplate中添加了Button按钮要实现页面的跳转,后台代码怎么写?

asp.netC#中在Gridview中的ItemTemplate中添加了Button按钮要实现页面的跳转,后台代码怎么写?... asp.net C# 中在Gridview中的ItemTemplate中添加了Button按钮要实现页面的跳转,后台代码怎么写? 展开
 我来答
百度网友bdbee96
2011-05-02
知道答主
回答量:22
采纳率:0%
帮助的人:17.9万
展开全部
没太明白你说的“页面的跳转”的意思,下面是前段时间写的东东,是有关Gridview中的一些按钮的操作的后台代码,希望能帮到你。。。。
protected void GridView1_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
{
switch (e.CommandName)
{
case "del":
{
Common.ExecOaSQL(String.Format("exec proc_sync_del {0}", e.CommandArgument.ToString()), Label_Err);//exec proc_sync_del {0}是一个存储过程
BindGridToSource(Int32.Parse(Label_pageindex.Text));
} break; //case
case "stop":
{
Common.ExecOaSQL(String.Format("update table_sync_index set modifystatusid=1,statusid=3 where syncid={0}", e.CommandArgument.ToString()), Label_Err);
BindGridToSource(Int32.Parse(Label_pageindex.Text));
} break; //case
case "begin":
{
Common.ExecOaSQL(String.Format("update table_sync_index set modifystatusid=1,statusid=2 where syncid={0}", e.CommandArgument.ToString()), Label_Err);
BindGridToSource(Int32.Parse(Label_pageindex.Text));
} break; //case
case "update":
{
GridViewRow row = GridView1.Rows[Convert.ToInt32(e.CommandArgument)];
Response.Redirect(String.Format("sync_sms_update.aspx?syncid={0}&page={1}&chid={2}&statusid={3}",
GridView1.DataKeys[row.RowIndex].Values["syncid"].ToString(),
Label_pageindex.Text,
DropDownList_channel.SelectedValue,
DropDownList_status.SelectedValue
));
} break; //case
}
}

protected void GridView1_RowCreated(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//为模板列的按钮传参数
LinkButton bf_del = (LinkButton)e.Row.FindControl("linkbutton_del");
LinkButton bf_stop = (LinkButton)e.Row.FindControl("linkbutton_stop");
LinkButton bf_begin = (LinkButton)e.Row.FindControl("linkbutton_begin");
bf_del.CommandArgument = GridView1.DataKeys[e.Row.RowIndex]["syncid"].ToString();
bf_stop.CommandArgument = GridView1.DataKeys[e.Row.RowIndex]["syncid"].ToString();
bf_begin.CommandArgument = GridView1.DataKeys[e.Row.RowIndex]["syncid"].ToString();

int a = (int)GridView1.DataKeys[e.Row.RowIndex]["statusid"];
if (a < 2 || a > 3)
bf_del.Text = "";
if (a != 2)
bf_stop.Text = "";
if (a != 3)
bf_begin.Text = "";
}
}

protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过变色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#FFFF99';");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

//基于模板列的删除确认(不需要根据cell的编号进行取值,添加列的时候不受影响)
string v = GridView1.DataKeys[e.Row.RowIndex]["areaname"].ToString();
LinkButton bf = (LinkButton)e.Row.FindControl("linkbutton_del");
bf.Attributes.Add("onclick", "javascript:return confirm('你确认要删除[" + v + "]群发吗?')");
}
}
文档杂货摊
2011-05-02 · 超过16用户采纳过TA的回答
知道答主
回答量:82
采纳率:0%
帮助的人:46.9万
展开全部
考虑用客户端按钮实现例如 <input type="button" onclick='location.href="test.aspx?param=<%#Eval("Fild")%>"' >
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
zp6119126
2011-05-02 · 超过17用户采纳过TA的回答
知道答主
回答量:78
采纳率:0%
帮助的人:46.5万
展开全部
双击button控件,在click事件里写
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
yxlovezx
2011-05-01 · 超过25用户采纳过TA的回答
知道答主
回答量:117
采纳率:42%
帮助的人:45.1万
展开全部
你给button一个单击事件,在事件中跳转啊
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式