在asp.net webform中的 gridview 里面的一些基本操作

摘要:
                 收货人:               买家账号:                  网店店名:                    订单号:                  付款时间:&

<body>

<form runat="server">

<table cellspacing="0" cellpadding="0" border="0">

<tr>

<td>

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

Width="100%">

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

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

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

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

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

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

</asp:Panel>

</td>

</tr>

<tr>

<td>

<asp:Panel runat="server" Visible="false" Width="1626px">

<table align="center">

<tr>

<td class="style2">

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

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

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

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

<asp:RadioButton Text="未检测" 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 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 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 runat="server" 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 runat="server" 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 runat="server" 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 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 runat="server">

<table>

<tr>

<td>

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

</td>

<td>

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

</td>

<td>

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

</td>

<td align="right">

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

</td>

<td>

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

</td>

<td align="right">

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

</td>

<td>

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

</td>

<td>

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

</td>

</tr>

</table>

</asp:Panel>

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

<asp:Panel runat="server">

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

OnPageIndexChanging="CardID_PageIndexChanging" OnRowDataBound="CardID_RowDataBound"

DataKeyNames="tid" OnRowCommand="CardID_RowCommand">

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

<Columns>

<asp:TemplateField>

<HeaderTemplate>

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

</HeaderTemplate>

<ItemTemplate>

<asp:CheckBox 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 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 Text='<%# DataBinder.Eval(Container.DataItem, "isload")%>'

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

<asp:Label 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 runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1) + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label>

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

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

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

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

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

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

<asp:LinkButton 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;

}

}

}

免责声明:文章转载自《在asp.net webform中的 gridview 里面的一些基本操作》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Qt创建异形窗口一个体验好的Windows 任务栏缩略图开发心得下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

使用OpenXml操作Excel,以下方法用于在添加列时修改Cell的CellReference属性。

以下方法实现了递增Excel中单元格的CellReference的功能,只支持两位字母。 1 public static string CellReferenceIncrement(string cellReference) 2 { 3 Match m1 = Regex.Match(cellReference, "^([A-Z]+)");...

如何统计代码行执行的时间?

1.问题 请计算下列代码执行所耗费的时间,给出通用的解决方法? List<Int32> myList=new List<Int32>(); for(Int32 i=0;i<ICount;i++) { myList.Add(i); } 2.解决方法 using (OperationTimer op=new OperationT...

UpdatePanel的几个属性

UpdatePanel的RenderMode属性RenderMode Block:使用div包含内容 Inline:使用span包含内容 UpdatePanel的UpdateMode属性Conditional:表示只用UpdatePanel内的控件有回发的时候UpdatePanel才更新 Always:这是默认值表示页面上所有的控件回发都会引起Update...

springboot备份mysql后发送邮件并删除备份文件,支持win和Linux

首先加入springboot的邮箱依赖 <!--邮箱依赖--> <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail --> <dependency> <groupId>...

ubuntu下thrift的安装

ubuntu下thrift的安装 - 水木米 - 博客频道 - CSDN.NET ubuntu下thrift的安装 分类:c/c++2012-08-03 11:1751人阅读评论(0)收藏举报 1.下载源代码 http://thrift.apache.org/download/ 下载最新版本thrift-0.8.0.tar.gz 2.安装bo...

DELPHI 字符串分割处理

DELPHI 字符串分割处理 Code 1Function FindStr(BegSprStr,EdSpStr:String;var Source:String):String;  2var  3BegStr1Len,EdSpStr2Len,BegStr1Index,EdSpStr2index:integer;  4Temp:String;  5begi...