zoukankan      html  css  js  c++  java
  • 在asp.net webform中的 gridview 里面的一些基本操作

    <body>

    <form id="form1" runat="server">

    <table id="Table1" cellspacing="0" cellpadding="0" width="100%" border="0">

    <tr>

    <td>

    <asp:Panel ID="ToolbarPanel" runat="server" CssClass="buttonContainer" Wrap="False"

    Width="100%">

    <asp:Button ID="btnQuery" runat="server" CssClass="buttonOut" Text="查询" Width="40px"

    OnClick="btnQuery_Click"></asp:Button>

    <asp:Button ID="btnSave" runat="server" Enabled="False" CssClass="buttonOut" Text="保存"

    OnClick="btnSave_Click"></asp:Button>

    <asp:Button ID="Button2" runat="server" Enabled="False" CssClass="buttonOut" Text="检测身份证是否上传"

    OnClick="Button2_Click"></asp:Button>

    </asp:Panel>

    </td>

    </tr>

    <tr>

    <td>

    <asp:Panel ID="Panel1" runat="server" Visible="false" Height="187px" Width="1626px">

    <table align="center">

    <tr>

    <td class="style2">

    <font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;是否上传身份证:

    <%-- <asp:Label ID="lblisload" runat="server" Text="Label" Style="color: Green"></asp:Label>--%>

    <asp:RadioButton Text="是" ID="RadioButton1" GroupName="a" runat="server" />

    <asp:RadioButton Text="否" ID="RadioButton2" GroupName="a" runat="server" />

    <asp:RadioButton Text="未检测" ID="RadioButton3" GroupName="a" runat="server" />

    <asp:Label runat="server" Style="color: Red">3个按钮是需要选择修改的时候选择用的!</asp:Label>

    </font>

    </td>

    </tr>

    <tr>

    <td class="style1">

    <font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    收货人:<asp:Label ID="lblshr" runat="server" Text="Label" Style="color: Green"></asp:Label></font>

    </td>

    </tr>

    <tr>

    <td class="style1">

    <font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    买家账号:<asp:Label ID="lblmjzh" runat="server" Text="Label" Style="color: Green"></asp:Label></font>

    </td>

    </tr>

    <tr>

    <td class="style1">

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    网店店名<font size="4">:<asp:Label ID="lblwddm" runat="server" Style="color: Green" Text="Label"></asp:Label>

    </font>

    </td>

    </tr>

    <tr>

    <td class="style2">

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    订单号<font size="4">:<asp:Label ID="lblddh" runat="server" Style="color: Green" Text="Label"></asp:Label>

    </font>

    </td>

    </tr>

    <tr>

    <td class="style1">

    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    付款<font size="4">时间:<asp:Label ID="lblfksj" runat="server" Style="color: Green" Text="Label"></asp:Label>

    </font>

    </td>

    </tr>

    <tr>

    <td class="style2">

    <font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    下单时间:<asp:Label ID="lblxdsj" runat="server" Text="Label" Style="color: Green"></asp:Label></font>

    </td>

    </tr>

    <tr>

    <td class="style1">

    <font size="4">&nbsp;&nbsp;&nbsp;</font>

    </td>

    </tr>

    <tr>

    <td class="style1">

    <font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>

    </td>

    </tr>

    </table>

    </asp:Panel>

    </td>

    </tr>

    <tr>

    <td>

    <asp:Panel ID="Panel2" runat="server">

    <table>

    <tr>

    <td>

    <font size="2">买家账号:<asp:TextBox ID="mjzh" runat="server" CssClass="flat"></asp:TextBox></font>

    </td>

    <td>

    <font size="2">收货 人:<asp:TextBox ID="shr" runat="server" CssClass="flat"></asp:TextBox></font>

    </td>

    <td>

    <font size="2">订单编号:<asp:TextBox ID="ddbh" runat="server" CssClass="flat"></asp:TextBox></font>

    </td>

    <td align="right">

    <font size="2">开始日期:</font>

    </td>

    <td>

    <asp:TextBox ID="txtzdrq1" runat="server" CssClass="flat" Width="90"></asp:TextBox>&nbsp;

    </td>

    <td align="right">

    <font size="2">截止日期:</font>

    </td>

    <td>

    <asp:TextBox ID="txtzdrq2" runat="server" CssClass="flat" Width="90"></asp:TextBox>

    </td>

    <td>

    <asp:Button ID="Button1" runat="server" Text="查询" CssClass="QueryCss" OnClick="Button1_Click" />

    </td>

    </tr>

    </table>

    </asp:Panel>

    <!--OnRowEditing="CardID_RowEditing"-->

    <asp:Panel ID="panel3" runat="server">

    <asp:GridView ID="CardID" runat="server" AllowPaging="True" PageSize="20" AutoGenerateColumns="False"

    OnPageIndexChanging="CardID_PageIndexChanging" Width="1805px" OnRowDataBound="CardID_RowDataBound"

    DataKeyNames="tid" OnRowCommand="CardID_RowCommand">

    <HeaderStyle HorizontalAlign="Center" BackColor="SkyBlue"></HeaderStyle>

    <Columns>

    <asp:TemplateField>

    <HeaderTemplate>

    <asp:CheckBox ID="chkAll" runat="server" AutoPostBack="True" OnCheckedChanged="chkAll_CheckedChanged" />

    </HeaderTemplate>

    <ItemTemplate>

    <asp:CheckBox ID="chkItem" runat="server" />

    </ItemTemplate>

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:TemplateField>

    <asp:TemplateField HeaderText="序号">

    <ItemTemplate>

    <%#Container.DataItemIndex+1%>

    </ItemTemplate>

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:TemplateField>

    <asp:TemplateField HeaderText="编辑">

    <ItemTemplate>

    <asp:LinkButton ID="lbtnQianRu" runat="server" CommandName="tid" CommandArgument='<%# Eval("tid") %>'>详情</asp:LinkButton>

    </ItemTemplate>

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:TemplateField>

    <%-- <asp:CommandField HeaderText="编辑" ItemStyle-HorizontalAlign="Center" ShowEditButton="True"

    EditText="详情">

    <ItemStyle HorizontalAlign="Center" />

    </asp:CommandField>--%>

    <asp:TemplateField HeaderText="是否上传身份证" SortExpression="a.isload Desc">

    <ItemTemplate>

    <asp:Label ID="lblIsload" Text='<%# DataBinder.Eval(Container.DataItem, "isload")%>'

    runat="server"></asp:Label>

    <asp:Label ID="lblisloadID" Visible="false" Text='<%# DataBinder.Eval(Container.DataItem, "isload")%>'

    runat="server"></asp:Label>

    </ItemTemplate>

    <ItemStyle HorizontalAlign="Center" />

    </asp:TemplateField>

    <asp:BoundField DataField="receiver_name" HeaderText="收货人" SortExpression="receiver_name"

    ItemStyle-HorizontalAlign="Center">

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:BoundField>

    <asp:BoundField DataField="buyer_nick" HeaderText="买家账号" SortExpression="buyer_nick"

    ItemStyle-HorizontalAlign="Center">

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:BoundField>

    <asp:BoundField DataField="seller_nick" HeaderText="网店店名" SortExpression="seller_nick"

    ItemStyle-HorizontalAlign="Center">

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:BoundField>

    <asp:BoundField DataField="tid" HeaderText="订单号" SortExpression="tid" ItemStyle-HorizontalAlign="Center">

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:BoundField>

    <asp:BoundField DataField="pay_time" HeaderText="付款时间" SortExpression="pay_time"

    ItemStyle-HorizontalAlign="Center">

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:BoundField>

    <asp:BoundField DataField="modified" HeaderText="下单时间" SortExpression="modified"

    ItemStyle-HorizontalAlign="Center">

    <ItemStyle HorizontalAlign="Center" Height=""></ItemStyle>

    </asp:BoundField>

    </Columns>

    <%-- <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />

    <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />

    <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />

    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />--%>

    <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />

    <PagerTemplate>

    <br />

    <asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>

    <asp:LinkButton ID="lbnFirst" runat="Server" Text="首页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'

    CommandName="Page" CommandArgument="First"></asp:LinkButton>

    <asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'

    CommandName="Page" CommandArgument="Prev"></asp:LinkButton>

    <asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>'

    CommandName="Page" CommandArgument="Next"></asp:LinkButton>

    <asp:LinkButton ID="lbnLast" runat="Server" Text="尾页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>'

    CommandName="Page" CommandArgument="Last"></asp:LinkButton>

    </PagerTemplate>

    </asp:GridView>

    </asp:Panel>

    </td>

    </tr>

    </table>

    </form>

    </body>

     

    后台代码.cs文件

    //窗体的加载事件

    protected new void Page_Load(object sender, EventArgs e)

    {

    base.Page_Load(sender, e);

    if (!IsPostBack)

    {

    this.txtzdrq2.Text = DateTime.Now.ToString();

    DateTime t = DateTime.Now.AddDays(-7);

    this.txtzdrq1.Text = t.ToString();

    }

    }

    //顶部的查询按钮

    protected void btnQuery_Click(object sender, EventArgs e)

    {

    Panel1.Visible = false;

    Panel2.Visible = true;

    panel3.Visible = true;

    Button2.Enabled = true;

    btnQuery.Enabled = true;

    btnSave.Enabled = false;

    this.mjzh.Text = "";

    this.shr.Text = "";

    this.ddbh.Text = "";

    string sql = "";

    sql = @"select isload, receiver_name, buyer_nick, seller_nick,tid,pay_time ,modified from tbtrade order by modified desc";

    DataTable dt = IFACE.DBUtility.DbHelperSQL.QueryDT(sql);

    if (dt != null && dt.Rows.Count > 0)

    {

    CardID.DataSource = dt;

    CardID.DataBind();

    }

    }

    //定义绑定数据的方法,里面包括模糊查询

    public void bind()

    {

    string sql = "";

    sql = @"select isload, receiver_name, buyer_nick, seller_nick,tid,pay_time ,modified from tbtrade where 1=1";

    if (mjzh.Text.Trim().Replace("'", "") != null && mjzh.Text.Trim().Replace("'", "") != "")

    {

    sql += "and buyer_nick like'" + mjzh.Text.Trim().Replace("'", "") + "'";

    }

    if (shr.Text.Trim().Replace("'", "") != null && shr.Text.Trim().Replace("'", "") != "")

    {

    sql += "and receiver_name like'" + shr.Text.Trim().Replace("'", "") + "'";

    }

    if (ddbh.Text.Trim().Replace("'", "") != null && ddbh.Text.Trim().Replace("'", "") != "")

    {

    sql += "and tid like'" + ddbh.Text.Trim().Replace("'", "") + "'";

    }

    if (this.txtzdrq1.Text != "" && this.txtzdrq2.Text != "")

    {

    sql += "and pay_time between '" + txtzdrq1.Text.Trim() + "' and '" + txtzdrq2.Text.Trim() + "'";

    }

    else

    {

    sql += "order by modified desc";

    }

    DataTable dt = IFACE.DBUtility.DbHelperSQL.QueryDT(sql);

    if (dt != null && dt.Rows.Count > 0)

    {

    CardID.DataSource = dt;

    CardID.DataBind();

    }

    }

    //下面的查询按钮验证选择的日期框和查询所有的文本框里面输入的信息

    protected void Button1_Click(object sender, EventArgs e)

    {

    if (txtzdrq1.Text == "*")

    {

    txtzdrq1.Text = "";

    }

    if (txtzdrq2.Text == "*")

    {

    txtzdrq2.Text = "";

    }

    if (txtzdrq1.Text != "")

    {

    if (Convert.ToDateTime(txtzdrq1.Text) > DateTime.Now)

    {

    Response.Write("<script>alert('开始日期不能大于当前日期')</script>");

    return;

    }

    }

    if (txtzdrq2.Text != "" && txtzdrq2.Text != "")

    {

    if (Convert.ToDateTime(txtzdrq1.Text) > Convert.ToDateTime(txtzdrq2.Text))

    {

    Response.Write("<script>alert('开始日期不能大于结束日期')</script>");

    return;

    }

    }

    Button2.Enabled = true;

    bind();

    }

    //分页

    protected void CardID_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

    CardID.PageIndex = e.NewPageIndex;

    bind();

    }

    //是否上传身份证的状态检测

    protected void CardID_RowDataBound(object sender, GridViewRowEventArgs e)

    {

    #region 在控件里面显示的已上传,未上传,未检测

    Label lblIsload = (Label)e.Row.FindControl("lblIsload");//是否上传

    if (e.Row.RowType == DataControlRowType.DataRow)

    {

    if (lblIsload.Text.Trim().ToString().ToLower() == "true")

    {

    lblIsload.Text = "是";

    }

    else if (lblIsload.Text.Trim().ToString().ToLower() == "")

    {

    lblIsload.Text = "未检测";

    lblIsload.ForeColor = System.Drawing.Color.Red;

    }

    else

    {

    lblIsload.Text = "否";

    lblIsload.ForeColor = System.Drawing.Color.Red;

    }

    //if (e.Row.Cells[2].Text.ToString() == "True")

    //{

    // e.Row.Cells[2].Text = "是";

    //}

    //else if (e.Row.Cells[2].Text.ToString() == "False")

    //{

    // e.Row.Cells[2].Text = "否";

    //}

    //else if (e.Row.Cells[2].Text.ToString() != "False" || e.Row.Cells[1].Text.ToString() != "True")

    //{

    // e.Row.Cells[2].Text = "未检测";

    //}

    e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='SkyBlue'");

    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

    }

    #endregion

    }

    //点击编辑将值传给panel1里面的每个对应的文本框

    //protected void CardID_RowEditing(object sender, GridViewEditEventArgs e)

    //{

    // Panel1.Visible = true;

    // btnSave.Enabled = true;

    // Button2.Enabled = false;

    // Panel2.Visible = false;

    // panel3.Visible = false;

    // //string lab = ((Label)CardID.Rows[e.NewEditIndex].Cells[3].FindControl("lblIsload")).Text;

    // //this.lblisload.Text = lab;

    // string isloadid = ((Label)CardID.Rows[e.NewEditIndex].Cells[3].FindControl("lblisloadID")).Text;

    // switch (isloadid)

    // {

    // case "True":

    // RadioButton1.Checked = true;

    // break;

    // case "False":

    // RadioButton2.Checked = true;

    // break;

    // default:

    // RadioButton3.Checked = true;

    // break;

    // }

    // this.lblshr.Text = this.CardID.Rows[e.NewEditIndex].Cells[4].Text;

    // this.lblmjzh.Text = this.CardID.Rows[e.NewEditIndex].Cells[5].Text;

    // this.lblwddm.Text = this.CardID.Rows[e.NewEditIndex].Cells[6].Text;

    // this.lblddh.Text = this.CardID.Rows[e.NewEditIndex].Cells[7].Text;

    // this.lblfksj.Text = this.CardID.Rows[e.NewEditIndex].Cells[8].Text;

    // this.lblxdsj.Text = this.CardID.Rows[e.NewEditIndex].Cells[9].Text;

    //}

    //保存修改的数据

    protected void btnSave_Click(object sender, EventArgs e)

    {

    string a = this.RadioButton1.Checked == true ? "1" : this.RadioButton2.Checked == true ? "0" : this.RadioButton3.Checked == true ? "null" : "";

    if (a != string.Empty)

    {

    string sql = @"update tbtrade set isload=" + a + " where tid='" + this.lblddh.Text + "'";

    int rows = IFACE.DBUtility.DbHelperSQL.ExecuteSql(sql);

    if (rows > 0)

    {

    Response.Write("<script>alert('修改成功!')</script>");

    btnQuery_Click(null, null);

    }

    else

    {

    Response.Write("<script>alert('修改失败!')</script>");

    }

    }

    }

    //全选checkbox事件

    protected void chkAll_CheckedChanged(object sender, EventArgs e)

    {

    for (int i = 0; i < this.CardID.Rows.Count; i++)

    {

    ((CheckBox)CardID.Rows[i].FindControl("chkItem")).Checked =

    ((CheckBox)this.CardID.HeaderRow.FindControl("chkAll")).Checked;

    }

    }

    //验证身份证是否上传

    protected void Button2_Click(object sender, EventArgs e)

    {

    #region 选择checkbox验证身份证是否上传的状态

    for (int i = 0; i < this.CardID.Rows.Count; i++)

    {

    CheckBox cb = ((CheckBox)CardID.Rows[i].FindControl("chkItem")) as CheckBox;

    string tid = this.CardID.DataKeys[i].Value.ToString();//在datakeyname属性里面设置了tid

    if (cb != null && cb.Checked)

    {

    DataTable dt = DbHelperSQL.QueryDT("select isLoad,receiver_name from tbtrade where tid='" + tid + "'");

    if (dt.Rows.Count > 0)

    {

    try

    {

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://qingguanid.com/api/search.php?n=" + dt.Rows[0]["receiver_name"].ToString());

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    System.Text.Encoding encoding = System.Text.Encoding.GetEncoding("gb2312");

    System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream(), encoding);

    string htmlstr = reader.ReadToEnd();

    reader.Close();

    response.Close();

    int isload = 0;

    if (htmlstr.Contains("not found"))

    {

    isload = 0;

    }

    else

    {

    if (htmlstr.IndexOf(": confirmed") > -1)

    {

    isload = 1;

    }

    else

    {

    isload = 0;

    }

    }

    string sql = @"update tbtrade set isload=" + isload + " where tid='" + tid + "'";

    DbHelperSQL.ExecuteSql(sql);

    }

    catch (Exception error)

    {

    Response.Write(error.ToString());

    }

    }

    }

    }

    bind();

    #endregion

    }

    //传值给panel1里面对应的label控件

    protected void CardID_RowCommand(object sender, GridViewCommandEventArgs e)

    {

    if (e.CommandName == "tid")

    {

    GridViewRow drv = ((GridViewRow)(((LinkButton)(e.CommandSource)).Parent.Parent)); //此得出的值是表示那行被选中的索引值

    string tid = CardID.DataKeys[drv.RowIndex].Value.ToString(); //此获取的值为GridView中绑定数据库中的唯一标识

    Panel1.Visible = true;

    btnSave.Enabled = true;

    Button2.Enabled = false;

    Panel2.Visible = false;

    panel3.Visible = false;

    string isloadid = ((Label)CardID.Rows[drv.RowIndex].Cells[3].FindControl("lblisloadID")).Text;

    switch (isloadid)

    {

    case "True":

    RadioButton1.Checked = true;

    break;

    case "False":

    RadioButton2.Checked = true;

    break;

    default:

    RadioButton3.Checked = true;

    break;

    }

    this.lblshr.Text = this.CardID.Rows[drv.RowIndex].Cells[4].Text;

    this.lblmjzh.Text = this.CardID.Rows[drv.RowIndex].Cells[5].Text;

    this.lblwddm.Text = this.CardID.Rows[drv.RowIndex].Cells[6].Text;

    this.lblddh.Text = this.CardID.Rows[drv.RowIndex].Cells[7].Text;

    this.lblfksj.Text = this.CardID.Rows[drv.RowIndex].Cells[8].Text;

    this.lblxdsj.Text = this.CardID.Rows[drv.RowIndex].Cells[9].Text;

    }

    }

    }

     

  • 相关阅读:
    JeecgBoot 2.4 微服务正式版发布,基于SpringBoot的低代码平台
    JeecgBoot 常见问题Q&A
    docker安装rabbitmq延时队列插件
    docker安装nacos
    docker安装xxl-job-admin
    docker安装rabbitmq
    低代码开发平台有哪些?
    对比 jeecgboot 和国内外其它低代码平台的区别
    JimuReport积木报表 — API数据源报表带参制作
    JimuReport积木报表 — API数据源报表制作
  • 原文地址:https://www.cnblogs.com/hbh123/p/5191104.html
Copyright © 2011-2022 走看看