C#中gridview常用的跳转方式
来源:互联网 发布:java建站 编辑:程序博客网 时间:2024/05/16 06:32
一般情况,在做一个页面的时候,常常会遇到跳转的问题。下面是常用方式:
<asp:GridView ID="GridVehicleServiceSite" runat="server" AutoGenerateColumns="false"
DataKeyNames="SS_ID" GridLines="None" Width="100%" CssClass="wzylw" OnRowCommand="GridVehicleServiceSite_RowCommand"
OnSelectedIndexChanged="GridVehicleServiceSite_SelectedIndexChanged">
<HeaderStyle HorizontalAlign="Center" Height="20px" />
<RowStyle HorizontalAlign="Center" Height="20px" />
<Columns>
//方式一:可以只是跳转,不需要判断。
<asp:TemplateField HeaderText="<%$ Resources:locationText,SSMAP %>">
<ItemTemplate>
<a href='../VehicleActivity/LocationPage.aspx?longitude=<%#DataBinder.Eval(Container.DataItem,"SS_LONG") %>&latitude=<%#DataBinder.Eval(Container.DataItem,"SS_LAT") %>' target="blank">
<img src="../images/boll1.gif" style="cursor: hand;" alt="" /></a>
</ItemTemplate>
</asp:TemplateField>
//方式二:具有某些判断行为,再进行跳转,此方法比较适合。
<asp:TemplateField HeaderText="行驶轨迹">
<ItemTemplate>
<asp:ImageButton runat="server" CommandName="history" ID="history" ImageUrl="~/images/boll1.gif"
CommandArgument='<%# Eval("vi_start_time")+","+Eval("vi_end_time")+","+ Eval("vi_license")%>'
CausesValidation="false" CssClass="wzylw_Change" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台代码:
protected void GridVehicleServiceSite_RowCommand(object sender, GridViewCommandEventArgs e)
{
//===========20120906 begin add for 查看历史轨迹================
// 点击修改
if (e.CommandName.ToLower() == "history")
{
string[] value = e.CommandArgument.ToString().Split(',');
if (string.IsNullOrEmpty(value[0]) || string.IsNullOrEmpty(value[1]) || string.IsNullOrEmpty(value[2]))
Response.Write("<script>alert('开始时间、结束时间、车牌号不能为空!')</script>");
else
Response.Write("<script> window.open('DFVehicleTracks.aspx?st=" + value[0] + "&et=" + value[1] + "&v=" + value[2] + "','_blank','height=550,width=850,top=0,left=0,toolbar=no,menubar=no,scrollbars=yes');</script>");
}
//===========20120906 end add for 查看历史轨迹================
}
protected void GridVehicleServiceSite_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
//===========20120906 begin add for 查看历史轨迹================
ImageButton ibtn = (ImageButton)e.Row.FindControl("history");
if (e.Row.Cells[3].Text == "结束")
{
ibtn.Enabled = true;
}
else
{
ibtn.Enabled = false;
}
//===========20120906 end add for 查看历史轨迹================
}
}
}
另外还有一种方式,是gridview自带的linkbutton,但是这个按钮加载时,会检查绑定路径的准确性。如果发现有错误路径,会导致这个页面加载出错。故不推荐使用,可以用<a></a>标签代替
- C#中gridview常用的跳转方式
- swift 常用的跳转方式。
- Gridview中点击编辑实现页面跳转的几种方式总结
- 跳转页面的几种常用方式
- js方式的页面跳转常用整理
- Android页面跳转的常用方式
- JSP常用的几种跳转方式
- c# 中各种类型的常用转换方式
- JSP常用跳转方式
- JSP常用跳转方式
- 常用界面跳转方式
- JSP常用跳转方式
- JSP常用跳转方式
- jsp常用跳转方式
- JSP常用跳转方式
- JSP常用跳转方式
- 在spring mvc controller中常用的几种跳转方式
- Asp.net中GridView的跳转列绑定格式
- php中heredoc的使用方法
- java.util.concurrent 多线程框架---线程池编程(三)
- poj2964 日历问题
- asp.net 删除文件夹导致session失效 解决办法
- web开发学习--循序渐进
- C#中gridview常用的跳转方式
- HDU 1286 找新朋友
- Ubuntu 手动分区方法
- 多步 OLE DB 操作产生错误。如果可能,请检查每个 OLE DB 状态值。没有工作被完成
- 搜索引擎-倒排索引基础知识
- 梦断代码--一个程序员的自白 (三)
- 演示一个矢量(Vector)的基本操作
- OpenGL ES 绘制多边形
- 不使用man 3 printf的函数,实现一个简单的printf函数