asp.net C# 中在Gridview中的ItemTemplate中添加了Button按钮要实现页面的跳转,后台代码怎么写?
asp.netC#中在Gridview中的ItemTemplate中添加了Button按钮要实现页面的跳转,后台代码怎么写?...
asp.net C# 中在Gridview中的ItemTemplate中添加了Button按钮要实现页面的跳转,后台代码怎么写?
展开
4个回答
展开全部
没太明白你说的“页面的跳转”的意思,下面是前段时间写的东东,是有关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 + "]群发吗?')");
}
}
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 + "]群发吗?')");
}
}
展开全部
考虑用客户端按钮实现例如 <input type="button" onclick='location.href="test.aspx?param=<%#Eval("Fild")%>"' >
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
双击button控件,在click事件里写
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你给button一个单击事件,在事件中跳转啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询