zoukankan      html  css  js  c++  java
  • 关于GridView模板的一些总结

    1、模板中放置LinkButton

    <ItemTemplate>

      <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl='<%#Eval("ID","***.aspx?id={0}")%>' Text="转到页面"/>

    </ItemTemplate>

    有两个参数的情况:<%#string.Format("***.aspx?id1={0}&id2={1}",Eval("id1"),Eval(id2))%>

    2、DropDownList添加一列

    ListItem item=new ListItem("--请选择-","0");

    DropDownList1.Items.Insert(0,item);

    3、GridView中没有数据行的处理

    DataTable table;

    if(table.Rows.Count==0)

    {

      table=table.Clone();

      table.Rows.Add(table.NewRow());

      GridView1.DataSource=table;

      GridView1.DataBind();

      int ColumnCount=table.Columns.Count;

      GridView1.Rows[0].Cells.Clear();

      GridView1.Rows[0].Cells.Add(new TableCell());

      GridView1.Rows[0].Cells[0].ColumnSpan="没有数据";

      GridView1.Rows[0].Cells[0].Style.Add("txt_align","center");

      GridView1.Rows[0].Cells[0].Style.Add("height","30px");

      GridView1.Rows[0].Cells[0].Style.Add("color","red");

    }

    else

    {

      GridView1.DataSource=table;

      GridView1.DataBind();

    }

    4、GridView模板中通过e.CommandArgument获取行的索引

    第一种方法:<asp:LinkButton ------------------------CommandName="..." CommandArgument="<%#((GridViewRow)Container).RowIndex%>"></asp:LinkButton>

          后台:int rowIndex=Convert.ToInt32(e.CommandArgument);

    第二种方法:使用GridView的RowCommand事件

          GridViewRow gvRow=(GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent);

          int rowIndex=gvRow.RowIndex;

    GridView中DataKeyNames="主键",获取主键:string id=((GridView)sender)DataKeys[rowIndex].values["主键名"].Tostring();

    5、在RowEditing中获取编辑行的索引

      int rowIndex=e.NewEditIndex;

    6、在GridView模板中,CommandName不能是Select、Delete、Update、Edit,这四个事件是GridView中自带的CommandName

    7、模板中放置LinkButton,通过RowCommand事件判断e.CommandName,用switch...case语句判断事件类型进行操作

    8、Text='<%#int.Parse((Eval("result")).Tostring())==1?"是":"否"%>'

    9、日期:<%#Eval("CreateDate","{0:yyyy-MM-dd}")%>

  • 相关阅读:
    SpringMVC(二)
    SpringMVC(一)
    Mybatis之mapper.xml配置文件中的#{}和${}
    Mybatis(二)
    Mybatis(一)
    Linux部署项目
    BOS物流项目第十三天
    Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd'
    景点API支持查询携程旅游门票景点详情
    Html引入百度富文本编辑器ueditor及自定义工具栏
  • 原文地址:https://www.cnblogs.com/jsping/p/2524598.html
Copyright © 2011-2022 走看看