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

Width="100%">

OnClick="btnQuery_Click">

OnClick="btnSave_Click">

OnClick="Button2_Click">

          是否上传身份证:

<%-- --%>

3个按钮是需要选择修改的时候选择用的!

                 

收货人:

               

买家账号:

                  

网店店名:

                    

订单号:

                  

付款时间:

               

下单时间:

   

      

买家账号:

收货 人:

订单编号:

开始日期:

 

截止日期:

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

DataKeyNames="tid" OnRowCommand="CardID_RowCommand">

<%#Container.DataItemIndex+1%>

详情

<%--

EditText="详情">

--%>

runat="server">

runat="server">

ItemStyle-HorizontalAlign="Center">

ItemStyle-HorizontalAlign="Center">

ItemStyle-HorizontalAlign="Center">

ItemStyle-HorizontalAlign="Center">

ItemStyle-HorizontalAlign="Center">

<%--

--%>


CommandName="Page" CommandArgument="First">

CommandName="Page" CommandArgument="Prev">

CommandName="Page" CommandArgument="Next">

CommandName="Page" CommandArgument="Last">

 

后台代码.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("");

return;

}

}

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

{

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

{

Response.Write("");

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("");

btnQuery_Click(null, null);

}

else

{

Response.Write("");

}

}

}

//全选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;

}

}

}

 

转载于:https://www.cnblogs.com/hbh123/p/5191104.html

你可能感兴趣的:(php,数据库)