后台为GridView设置链接
来源:互联网 发布:程序员不培训班 编辑:程序博客网 时间:2024/05/18 11:30
GridView链接列界面如下:
HTML代码:
<asp:GridView ID="gv" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" PageSize="15" OnSorting="GridView1_Sorting" ShowFooter="True" OnRowDataBound="GV_OrgGridView_RowDataBound"> <FooterStyle CssClass="GridViewFooterStyle" HorizontalAlign="Center" /> <RowStyle CssClass="GridViewRowStyle" HorizontalAlign="Center" /> <PagerStyle CssClass="GridViewPagerStyle" /> <SelectedRowStyle CssClass="GridViewSelectedRowStyle" /> <HeaderStyle CssClass="GridViewHeaderStyle" /> <EditRowStyle CssClass="GridViewEditRowStyle" /> <AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" /> <Columns> <asp:BoundField HeaderText="序号" DataField="rn" ItemStyle-Width="3%"></asp:BoundField> <asp:BoundField HeaderText="养殖场名称" DataField="FARM_NAME" ItemStyle-Width="8%"></asp:BoundField> <asp:BoundField HeaderText="所属地区" DataField="REGION_NAME" ItemStyle-Width="8%"></asp:BoundField> <asp:BoundField HeaderText="负责人" DataField="PRINCIPAL" SortExpression="PRINCIPAL" ItemStyle-Width="5%"></asp:BoundField> <asp:BoundField HeaderText="联系电话" DataField="PRINCIPAL_TEL" SortExpression="PRINCIPAL_TEL" ItemStyle-Width="8%"> </asp:BoundField> <asp:BoundField HeaderText="存栏总数" DataField="STOCKCOUNT" Visible="false" SortExpression="STOCKCOUNT" ItemStyle-Width="6%"></asp:BoundField> <asp:HyperLinkField DataTextField="STOCKCOUNT" HeaderText="存栏总数" ItemStyle-Width="6%" ItemStyle-CssClass="FontC"> </asp:HyperLinkField> <asp:HyperLinkField HeaderText="母猪" DataTextField="NUM3" ItemStyle-Width="3%" ItemStyle-CssClass="FontC"> </asp:HyperLinkField> <asp:HyperLinkField HeaderText="肉猪" DataTextField="NUM2" SortExpression="NUM2" ItemStyle-Width="3%" ItemStyle-CssClass="FontC"> </asp:HyperLinkField> <asp:HyperLinkField HeaderText="仔猪" DataTextField="NUM1" SortExpression="NUM1" ItemStyle-Width="3%" ItemStyle-CssClass="FontC"> </asp:HyperLinkField> <asp:HyperLinkField HeaderText="公猪" DataTextField="NUM4" SortExpression="NUM4" ItemStyle-Width="3%" ItemStyle-CssClass="FontC"> </asp:HyperLinkField> <asp:BoundField HeaderText="当月出栏数" DataField="MONTHSTOCK" SortExpression="MONTHSTOCK" ItemStyle-Width="6%"></asp:BoundField> <asp:BoundField HeaderText="当年出栏数" DataField="YEARSTOCK" SortExpression="YEARSTOCK" ItemStyle-Width="6%"></asp:BoundField> <asp:BoundField HeaderText="变更时间" DataField="CREATETIME" SortExpression="CREATETIME" ItemStyle-Width="10%"></asp:BoundField> <asp:BoundField HeaderText="状态" DataField="STATE" SortExpression="STATE" ItemStyle-Width="4%"></asp:BoundField> <asp:TemplateField HeaderText="操作" ItemStyle-Width="10%"> <ItemTemplate> <asp:HyperLink ID="isEdit" runat="server" Visible=<%# (Eval("STATE").ToString() == "注销") ? false : true %> Text="编辑" NavigateUrl=<%# "PigUserEdit.aspx?t=10&id="+Eval("id") %>></asp:HyperLink> <asp:LinkButton ID="delInfo" runat="server" CausesValidation="false" CommandArgument='<%# Eval("id") %>' Visible='<%# (Eval("STATE").ToString() == "注销") ? false : true %>' OnClick="delInfo_Click" Text="注销" OnClientClick="return confirm('确认要注销吗?');"></asp:LinkButton> <asp:HyperLink ID="isChange" runat="server" Visible=<%# (Eval("STATE").ToString() == "注销") ? false : true %> Text="存栏数变更" NavigateUrl=<%# "PigUserChange.aspx?t=10&id="+Eval("id") %>></asp:HyperLink> <%-- <a id="isChange" href="PigUserChange.aspx?t=10&id=<%# Eval("id")%>"> <span>存栏数变更</span></a> --%> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>后台代码:
protected void GV_OrgGridView_RowDataBound(object sender, GridViewRowEventArgs e) { //控制excel中数字显示(不显示为数学归纳法) for (int i = 0; i < e.Row.Cells.Count; i++) { if (e.Row.RowType == DataControlRowType.DataRow) e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@"); } if (e.Row.RowType == DataControlRowType.DataRow) { DataRowView myrows = (DataRowView)e.Row.DataItem; //设置存栏总数链接 if (Convert.ToInt32(myrows["STOCKCOUNT"].ToString() == string.Empty ? "0" : myrows["STOCKCOUNT"].ToString()) > 0) { //设置“存栏总数”的链接 HyperLink hp = (HyperLink)e.Row.Cells[6].Controls[0]; string url = string.Format("HistoryInfo.aspx?{0}={1}&{2}={3}", UrlParameter.STOCK_ID, myrows["ID"],//参数值 UrlParameter.ANIMAL_TYPE, 10); hp.NavigateUrl = url; } //设置仔猪链接 if (Convert.ToInt32(myrows["NUM1"].ToString() == string.Empty ? "0" : myrows["NUM1"].ToString()) > 0) { //设置“仔猪”的链接 HyperLink hp = (HyperLink)e.Row.Cells[9].Controls[0]; string url = string.Format("HistoryInfo.aspx?{0}={1}&{2}={3}&{4}={5}", UrlParameter.STOCK_ID, myrows["ID"], UrlParameter.STOCK_KIND, "仔猪", UrlParameter.ANIMAL_TYPE, 10); hp.NavigateUrl = url; } } // 合计 if (e.Row.RowType == DataControlRowType.Footer) { e.Row.Cells[0].Text = "合计"; e.Row.Cells[6].Text = StockCount.ToString(); e.Row.Cells[7].Text = MuZhuCount.ToString(); e.Row.Cells[8].Text = RouZhuCount.ToString(); e.Row.Cells[9].Text = ZaiZhuCount.ToString(); e.Row.Cells[10].Text = GongZhuCount.ToString(); e.Row.Cells[11].Text = MonthCount.ToString(); e.Row.Cells[12].Text = YearCount.ToString(); } }
UrlParameter参数键:
/// <summary>/// url参数键/// </summary>public class UrlParameter{ /// <summary> ///ID /// </summary> public const string STOCK_ID = "sid"; /// <summary> ///类型 /// </summary> public const string STOCK_KIND = "skind";}
HistoryInfo取值:
int id = RequestInt(UrlParameter.STOCK_ID);//id string kind = RequestString(UrlParameter.STOCK_KIND);//类型
0 0
- 后台为GridView设置链接
- 使用JS为GridView列设置链接
- 怎么为GridView中的链接设置多个参数?
- gridview 后台绑定链接以及处理
- IE10.Gridview后台设置行高
- ASP.NET下GridView中设置链接
- 设置prestashop 后台为中文
- GridView单元格border设置为none
- listview gridview 设置背景颜色为透明
- 设置GridView的item为正方形
- GridView 设置其高度属性为 wrap_content
- 如何设置Tomcat为后台服务启动
- 将某一线程设置为后台线程
- Link2005----设置为动态链接和静态链接的问题
- GridView的列数设置为auto_fit会提升性能?
- WPF GridView的宽度设置为按比例分配
- 关于为gridView中的Item设置点击事件
- C# DEV 关于设置gridview 指定单元格字体为红色
- ScaleType设置无效
- Oracle各种类型的运用|char、varchar、text和nchar、nvarchar、ntext的区别
- jQuery常用总结
- Android中Java和JS调用对方方法的简介
- 邮件开发:复杂邮件的一个示例
- 后台为GridView设置链接
- Activity生命周期
- 阿里云服务器使用OneinStack的lnmp一键安装包后查看nginx的并发数
- C/C++的就业,发展方向
- Java transient,Volatile关键字
- Understanding Steering Behaviors: Queue
- Linux下Java环境变量配置
- 001、iOS 在使用 performSelector时 异常"performSelector may cause a leak because its selector is unknown"
- 详解HttpURLConnection