c#大圣之路笔记——c# DataGrid checkbox 操作

  1 ///html
  2
  3 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xOEMStoreNominationForCAM.aspx.cs" EnableEventValidation="false" Inherits="PRCSales_external.Store.xOEMStoreNominationForCAM" %>
  4
  5 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6
  7 <html xmlns="http://www.w3.org/1999/xhtml">
  8 <head runat="server">
  9     <title>xOEM Store Nomination for CAM</title>
 10     <link href="../css/main.css" rel="stylesheet" type="text/css" />
 11     <link href="../css/Styles_1.css" rel="stylesheet" type="text/css" />
 12
 13     <script type="text/javascript" src="../js/jquery-1.8.2.js"></script>
 14     <script type="text/javascript" src="../js/LocationFilterQuarter.js"></script>
 15
 16     <script type="text/javascript">
 17
 18
 19             function CheckAll(chkObject) {
 20                 var checkArray = document.getElementsByTagName("input");
 21                 for (j = 0; j < checkArray.length; j++) {
 22                     if (checkArray[j].type == "checkbox" & checkArray[j] != chkObject ) {
 23                         if (chkObject.checked != checkArray[j].checked)
 24                             checkArray[j].checked = chkObject.checked;
 25                     }
 26                 }
 27             }
 28
 29
 30
 31
 32             function ShowWaiting() {
 33                 document.getElementById(‘doing‘).style.visibility = ‘visible‘;
 34             }
 35             function CloseWaiting() {
 36                 document.getElementById(‘doing‘).style.visibility = ‘hidden‘;
 37             }
 38             function MyOnload() {
 39                 document.getElementById(‘doing‘).style.visibility = ‘hidden‘;
 40             }
 41
 42             if (window.onload == null) {
 43                 window.onload = MyOnload;
 44             }
 45
 46     </script>
 47
 48
 49     <style type="text/css">
 50             #btnMark ,#btnUnmark
 51             {
 52                 margin-left:5px;
 53             }
 54
 55     </style>
 56
 57
 58 </head>
 59 <body>
 60     <form id="form1" runat="server">
 61     <table width="100%" id="Table1">
 62         <tr ><td style="height:30px; "><b>xOEM Store Nomination for CAM</b></td></tr>
 63         <tr>
 64          <tr style="HEIGHT: 1px; BACKGROUND-COLOR: #3366ff">
 65                     <td colSpan="4"><FONT style="BACKGROUND-COLOR: #ffffff" face="宋体"></FONT><FONT face="宋体"></FONT></td>
 66                 </tr>
 67         <tr>
 68                 <td class="fieldtitle" width="30%">Quarter:</td>
 69                 <td class="fieldtitle" width="20%"><asp:dropdownlist id="ddlQuarter" runat="server"  AutoPostBack="true"
 70                         onselectedindexchanged="ddlQuarter_SelectedIndexChanged"  onchange="initData(‘region‘)"></asp:dropdownlist></td>
 71                 <td class="fieldtitle" width="20%">
 72                     Region/Grid/City:
 73                 </td>
 74                 <td class="fieldtitle" colspan="3" width="30%">
 75                     <asp:DropDownList ID="ddlRegion" runat="server" CssClass="fieldList" onchange="initData(‘subregion‘)">
 76                     </asp:DropDownList>
 77                     <asp:DropDownList ID="ddlSubRegion" runat="server" CssClass="fieldList" style="display:none;" onchange="initData(‘grid‘)">
 78                     </asp:DropDownList>
 79                     <asp:DropDownList ID="ddlGrid" runat="server" CssClass="fieldList"  onchange="initData(‘pref‘)">
 80                     </asp:DropDownList>
 81                     <asp:DropDownList ID="ddlPref" runat="server" CssClass="fieldList" style="display:none;"  onchange="initData(‘city‘)">
 82                     </asp:DropDownList>
 83                     <asp:DropDownList ID="ddlCity" runat="server" CssClass="fieldList"  onchange="initData(‘county‘)">
 84                     </asp:DropDownList>
 85                     <asp:DropDownList ID="ddlCounty" runat="server" CssClass="fieldList" style="display:none;" onchange="initData(‘town‘)">
 86                     </asp:DropDownList>
 87                     <asp:DropDownList ID="ddlTown" runat="server" CssClass="fieldList" style="display:none;" onchange="initData(‘village‘)">
 88                     </asp:DropDownList>
 89                     <asp:DropDownList ID="ddlVillage" runat="server" CssClass="fieldList" style="display:none;" onchange="initData(‘village1‘)">
 90                     </asp:DropDownList>
 91
 92                     <asp:TextBox ID="txtWWID" runat="server" Style="display: none"></asp:TextBox>
 93                     <asp:TextBox ID="txtQuarter" runat="server" Style="display: none"></asp:TextBox>
 94                     <asp:TextBox ID="txtRegion" runat="server" Style="display: none"></asp:TextBox>
 95                     <asp:TextBox ID="txtSubRegion" runat="server" Style="display: none"></asp:TextBox>
 96                     <asp:TextBox ID="txtGrid" runat="server" Style="display: none"></asp:TextBox>
 97                     <asp:TextBox ID="txtPref" runat="server" Style="display: none"></asp:TextBox>
 98                     <asp:TextBox ID="txtCity" runat="server" Style="display: none"></asp:TextBox>
 99                     <asp:TextBox ID="txtCounty" runat="server" Style="display: none"></asp:TextBox>
100                     <asp:TextBox ID="txtTown" runat="server" Style="display: none"></asp:TextBox>
101                     <asp:TextBox ID="txtVillage" runat="server" Style="display: none"></asp:TextBox>
102                 </td>
103
104         </tr>
105         <tr>
106             <td class="fieldtitle" width="30%" >Store Name:</td>
107             <td class="fieldtitle" width="20%" colspan="1"><asp:TextBox ID="txtStorNm" runat="server"></asp:TextBox></td>
108             <td class="fieldtitle" width="20%" >Store ID:</td>
109             <td class="fieldtitle" width="30%"><asp:TextBox ID="txtStorID" runat="server"></asp:TextBox></td>
110         </tr>
111        <%-- <tr>
112             <td  class="fieldtitle" width="20%" colspan=""><asp:CheckBox ID="chkStore"  runat="server" CssClass="fieldtitle" Text="Show Unassigned Store Only"/></td>
113         </tr>--%>
114         <tr style="HEIGHT: 1px; BACKGROUND-COLOR: #3366ff">
115                     <td colSpan="4"><FONT style="BACKGROUND-COLOR: #ffffff" face="宋体"></FONT><FONT face="宋体"></FONT></td>
116                 </tr>
117         <tr>
118             <td class="fieldtitle" width="30%" colspan="1">Store list <asp:Label ID="lblCount" runat="server" CssClass="fieldList"></asp:Label>
119               <%-- <asp:Label ID="lblMessage" runat="server" CssClass="fieldList" ForeColor="Red" Text="季度店面标记"></asp:Label>  --%>
120                     <asp:Label ID="lblLeftTime" CssClass="fieldList" runat="server" ForeColor="Red"></asp:Label>
121             </td>
122
123             <td align="right" colspan="3" width="70%">
124             <asp:Button ID="btnSearch" runat="server" Text="Search"   CssClass="fieldButton" onclick="btnSearch_Click"  Width="80px"/>
125             <asp:Button ID="btnMark" runat="server" Text="Mark"   CssClass="fieldButton" onclick="btnMark_Click" Width="80px" />
126             <asp:Button ID="btnUnmark" runat="server" Text="Unmark" CssClass="fieldButton"   onclick="btnUnmark_Click" Width="80px" />
127             </td>
128         </tr>
129         <tr>
130             <td colspan="4">
131                 <asp:DataGrid ID="GridMain" runat="server" Width="100%"
132                     AutoGenerateColumns="false" PageSize="20" AllowPaging="true"
133                      onselectedindexchanged="GridMain_SelectedIndexChanged"  onpageindexchanged="GridMain_PageIndexChanged">
134                 <AlternatingItemStyle CssClass="datagridAlternating" />
135                 <HeaderStyle CssClass="tableHead" />
136                 <Columns>
137                     <asp:TemplateColumn>
138                    <HeaderStyle Width="20px"></HeaderStyle>
139                      <HeaderTemplate><asp:CheckBox ID ="checkAll" runat="server" onclick="CheckAll(this);" /></HeaderTemplate>
140                      <ItemTemplate><asp:CheckBox ID="chkSelected" runat="server"  /></ItemTemplate>
141                     </asp:TemplateColumn>
142                     <asp:BoundColumn DataField="stor_rgn_nm" HeaderText="Store Region">
143                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
144                     </asp:BoundColumn>
145                   <asp:BoundColumn DataField="stor_grid_cd" HeaderText="Store Grid">
146                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
147                     </asp:BoundColumn>
148                     <asp:BoundColumn DataField="stor_city_std_loc_nm" HeaderText="Store City">
149                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
150                     </asp:BoundColumn>
151                      <asp:BoundColumn DataField="stor_id" HeaderText="Store ID">
152                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
153                     </asp:BoundColumn>
154                      <asp:BoundColumn DataField="stor_nm" HeaderText="Store Name">
155                                     <ItemStyle HorizontalAlign="Center" Width="8%"></ItemStyle>
156                     </asp:BoundColumn>
157                     <asp:BoundColumn DataField="stor_addr" HeaderText="Store Addr">
158                                     <ItemStyle HorizontalAlign="Center" Width="8%"></ItemStyle>
159                     </asp:BoundColumn>
160                      <asp:BoundColumn DataField="brnd_nm" HeaderText="Store Brand">
161                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
162                     </asp:BoundColumn>
163                      <asp:BoundColumn DataField="xoem_store_tier" HeaderText="Store Tier">
164                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
165                     </asp:BoundColumn>
166                      <asp:BoundColumn DataField="remark" HeaderText="Store Bis Type">
167                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
168                     </asp:BoundColumn>
169                      <asp:BoundColumn DataField="oem_stor_id" HeaderText="OEM Store ID">
170                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
171                     </asp:BoundColumn>
172                      <asp:BoundColumn DataField="rep_nm" HeaderText="Store Manager">
173                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
174                     </asp:BoundColumn>
175                        <asp:BoundColumn DataField="slsprs_nm" HeaderText="SR Owner">
176                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
177                     </asp:BoundColumn>
178                        <asp:BoundColumn DataField="stor_sts" HeaderText="Store Status">
179                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
180                     </asp:BoundColumn>
181                        <asp:BoundColumn DataField="chnl_rgn_nm" HeaderText="Chnl Region">
182                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
183                     </asp:BoundColumn>
184                        <asp:BoundColumn DataField="chnl_grid_cd" HeaderText="Chnl Grid">
185                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
186                     </asp:BoundColumn>
187                     <asp:BoundColumn DataField="chnl_city_std_loc_nm" HeaderText="Chnl City">
188                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
189                     </asp:BoundColumn>
190                      <asp:BoundColumn DataField="gid_num" HeaderText="Chnl GID">
191                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
192                     </asp:BoundColumn>
193                      <asp:BoundColumn DataField="co_id" HeaderText="Chnl ID">
194                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
195                     </asp:BoundColumn>
196                        <asp:BoundColumn DataField="co_nm" HeaderText="Chnl Name">
197                                     <ItemStyle HorizontalAlign="Center" Width="7%"></ItemStyle>
198                     </asp:BoundColumn>
199                         <asp:BoundColumn DataField="co_addr" HeaderText="Chnl Addr">
200                                     <ItemStyle HorizontalAlign="Center" Width="7%"></ItemStyle>
201                     </asp:BoundColumn>
202                         <asp:BoundColumn DataField="co_cntct_person" HeaderText="Chnl Manager">
203                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
204                     </asp:BoundColumn>
205                      <asp:BoundColumn DataField="co_tel" HeaderText="Chnl Tel">
206                                     <ItemStyle HorizontalAlign="Center" Width="4%"></ItemStyle>
207                     </asp:BoundColumn>
208                      <asp:BoundColumn DataField="mbr_type_nm" HeaderText="Chnl Type">
209                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
210                     </asp:BoundColumn>
211                      <asp:BoundColumn DataField="chnl_sts" HeaderText="Chnl Status">
212                                     <ItemStyle HorizontalAlign="Center" Width="3%"></ItemStyle>
213                     </asp:BoundColumn>
214
215                 </Columns>
216                 <PagerStyle Position="TopAndBottom" Mode="NumericPages" />
217                 </asp:DataGrid>
218             </td>
219         </tr>
220
221     </table>
222     </form>
223      <div id=‘doing‘ style=‘z-index: 12000; left: 0px; width: 100%; cursor: wait; position: absolute;   top: 0px; height: 100%; filter: alpha(opacity=45); opacity: 0.5; color: #000000;  background-color: #FFFFFF;‘>
224         <table width=‘100%‘ height=‘100%‘ id="Table2">
225             <tr align=‘center‘ valign=‘middle‘>
226                 <td>
227                     <table id="Table3" class="loading">
228                         <tr align=‘center‘ valign=‘middle‘>
229                             <td>
230                                 <img src="../Images/Waitting.gif" />
231                             </td>
232                              <td>&nbsp;&nbsp;</td>
233                             <td valign="middle">
234                                 <span id=txtLoading0 style="font-size:14px; color: #800080; font-weight: bold;">页面正在加载数据,请稍候...</span>
235                                <br><span id=txtLoading1 style="font-size:14px; color: #800080;">Loading,please wait...</span>
236                             </td>
237                         </tr>
238                     </table>
239                 </td>
240             </tr>
241         </table>
242     </div>
243
244 </body>
245 </html>
  1 using System;
  2 using System.Collections.Generic;
  3 using System.Linq;
  4 using System.Web;
  5 using System.Web.UI;
  6 using System.Web.UI.WebControls;
  7 using CompIntelligenceWeb.User;
  8 using System.Data;
  9 using Intel.PRCSMS.Common;
 10 using System.Data.SqlClient;
 11 using Microsoft.ApplicationBlocks.Data;
 12
 13 namespace PRCSales_external.Store
 14 {
 15     public partial class xOEMStoreNominationForCAM : PageBase
 16     {
 17         private DataTable dataTable;
 18         private string tableName;
 19         private DateTime _openDate;
 20         private DateTime _cutOffDate;
 21
 22         protected void Page_Load(object sender, EventArgs e)
 23         {
 24             this.btnSearch.Attributes.Add("onclick", "ShowWaiting();");
 25             this.btnMark.Attributes.Add("onclick", "ShowWaiting();");
 26             this.btnUnmark.Attributes.Add("onclick", "ShowWaiting();");
 27             if (!IsPostBack)
 28             {
 29                 ViewState["WWID"] = ((AccessControler)this.Session["_accessctrl"]).GetWWID();
 30
 31                 this.txtWWID.Text = ViewState["WWID"].ToString();
 32
 33                 initData();
 34
 35                 initTable();
 36
 37                 gridBind();
 38
 39                 bindNextPage(0);
 40
 41                 if (ViewState["actionFlag"].ToString()=="1")
 42                 {
 43                     this.btnMark.Enabled = true;
 44                     this.btnUnmark.Enabled = true;
 45                 }
 46                 else
 47                 {
 48                     this.btnMark.Enabled = false;
 49                     this.btnUnmark.Enabled = false;
 50                 }
 51
 52             }
 53             else
 54             {
 55                 tableName = ViewState["TableName"].ToString();
 56                 dataTable = (DataTable)ViewState["DataTable"];
 57             }
 58         }
 59
 60
 61
 62         private void bindNextPage(int p)
 63         {
 64             tableName = ViewState["TableName"].ToString();
 65             dataTable = (DataTable)ViewState["DataTable"];
 66
 67             GridMain.DataSource = dataTable.DefaultView;
 68             GridMain.CurrentPageIndex = p;
 69             GridMain.DataBind();
 70
 71             ///标记Style设置
 72             NotedStyle();
 73         }
 74
 75
 76         private void initData()
 77         {
 78             SetCutOffDate();
 79             BindQuarter();
 80         }
 81         /// <summary>
 82         /// 标记功能的时间控制
 83         /// </summary>
 84         private void SetCutOffDate()
 85         {
 86             string sql = "SELECT TOP 1 open_dt, cls_dt,* FROM prc_frz_dt WHERE (frz_dt_type_id = 27) ORDER BY yyyyqq desc ";
 87             ViewState["actionFlag"] = "";
 88             using (IDataReader dr = SqlHelper.ExecuteReader(Application["DSN"].ToString(),CommandType.Text,sql))
 89             {
 90                 if (dr.Read())
 91                 {
 92                     _openDate = Convert.ToDateTime(dr["open_dt"]);
 93                     _cutOffDate = Convert.ToDateTime(dr["cls_dt"]);
 94                     if (_openDate >DateTime.Now)
 95                     {
 96                         lblLeftTime.Text = "暂时无法对店面进行标记,该操作尚未开始";
 97                     }
 98                     else if (_cutOffDate <DateTime.Now)
 99                     {
100                         lblLeftTime.Text = "店面标记操作已结束";
101                     }
102                     else
103                     {
104                         TimeSpan countDownSpan = _cutOffDate - DateTime.Now;
105                         //if (countDownSpan.Days -7 <0)
106                         //{
107                         //    lblLeftTime.Text = string.Format("距离店面可标记操作截止日还有{0}天{1}小时。",0,0);
108                         //}
109                         //else
110                         //{
111                             lblLeftTime.Text = string.Format("距离店面可标记操作截止日还有{0}天{1}小时",countDownSpan.Days,countDownSpan.Hours);
112                         //}
113                         ViewState["actionFlag"] = 1;
114                     }
115                 }
116                 else
117                 {
118                     lblLeftTime.Text = "店面标记的操作时间还未设定";
119                     ViewState["actionFlag"] = 0;
120                 }
121             }
122         }
123
124         private void BindQuarter()
125         {
126             ddlQuarter.DataSource = Quarter.GetQuarterList(Application["DSN"].ToString());
127             ddlQuarter.DataBind();
128             ddlQuarter.SelectedIndex = 0;
129
130             this.txtQuarter.Text = ddlQuarter.SelectedValue;
131
132         }
133
134         private void initTable()
135         {
136             tableName = "xOEMStoreNominationForCAM" + DateTime.UtcNow.ToString();
137             dataTable = new DataTable(tableName);
138
139             ViewState["TableName"] = tableName;
140             ViewState["DataTable"] = dataTable;
141         }
142
143         private void gridBind()
144         {
145                 dataTable = new DataTable();
146
147                 SqlConnection conn = new SqlConnection(Application["DSN"].ToString());
148                 SqlCommand cmd = new SqlCommand();
149                 SqlDataAdapter da = new SqlDataAdapter();
150                 cmd.CommandType = CommandType.StoredProcedure;
151                 cmd.CommandText = "prc_xoem_stor_nominate_qtr_list";
152                 cmd.Connection = conn;
153             try
154             {
155                 cmd.Parameters.AddWithValue("@wwid", ViewState["WWID"].ToString());
156                 cmd.Parameters.AddWithValue("@yyyyqq",ddlQuarter.SelectedValue);
157
158                 if (txtRegion.Text.Trim() == "ALL" || txtRegion.Text.Trim() == "")
159                 {
160                     cmd.Parameters.AddWithValue("@rgn_cd", DBNull.Value);
161                 }
162                 else
163                 {
164                     cmd.Parameters.AddWithValue("@rgn_cd", txtRegion.Text.Trim());
165                 }
166                 if (txtGrid.Text.Trim() == "ALL" || txtGrid.Text.Trim() == "")
167                 {
168                     cmd.Parameters.AddWithValue("@grid_cd", DBNull.Value);
169                 }
170                 else
171                 {
172                     cmd.Parameters.AddWithValue("@grid_cd", txtGrid.Text.Trim());
173                 }
174                 if (txtCity.Text.Trim() == "ALL" || txtCity.Text.Trim() == "")
175                 {
176                     cmd.Parameters.AddWithValue("@city_id", DBNull.Value);
177                 }
178                 else
179                 {
180                     cmd.Parameters.AddWithValue("@city_id", txtCity.Text.Trim());
181                 }
182                 if (txtStorID.Text.Trim() != "")
183                 {
184                     cmd.Parameters.AddWithValue("@stor_id", txtStorID.Text.Trim());
185                 }
186                 else
187                 {
188                     cmd.Parameters.AddWithValue("@stor_id", DBNull.Value);
189                 }
190                 if (txtStorNm.Text.Trim() != "")
191                 {
192                     cmd.Parameters.AddWithValue("@stor_nm", txtStorNm.Text.Trim());
193                 }
194                 else
195                 {
196                     cmd.Parameters.AddWithValue("@stor_nm", DBNull.Value);
197                 }
198
199                 da.SelectCommand = cmd;
200                 conn.Open();
201
202
203                 da.Fill(dataTable);
204
205                 this.lblCount.Text = "Total Number:" + dataTable.Rows.Count+ " ";
206
207                 ViewState["DataTable"] = dataTable;
208             }
209             catch
210             {
211
212             }
213             finally
214             {
215                 conn.Close();
216                 da.Dispose();
217                 cmd.Dispose();
218             }
219
220
221         }
222         /// <summary>
223         /// 提名标记
224         /// </summary>
225         /// <param name="sender"></param>
226         /// <param name="e"></param>
227         protected void btnMark_Click(object sender, EventArgs e)
228         {
229             int mkCount = 0;
230             //Dictionary<int, int> list = new Dictionary<int, int>();
231             for (int i = 0; i < GridMain.Items.Count; i++)
232             {
233                 CheckBox CB =(CheckBox)GridMain.Items[i].FindControl("chkSelected");
234                 if (CB.Checked==true)
235                 {
236                 //    list.Add(int.Parse(GridMain.Items[i].Cells[4].Text), int.Parse(GridMain.Items[i].Cells[18].Text));
237
238                     SqlParameter[] paraList = new SqlParameter[] {
239                              new SqlParameter("@yyyyqq",ddlQuarter.SelectedValue),
240                              new SqlParameter("@wwid",ViewState["WWID"].ToString()),
241                              new SqlParameter("@stor_id",GridMain.Items[i].Cells[4].Text.Trim()),
242                              new SqlParameter("@co_id",GridMain.Items[i].Cells[18].Text.Trim())
243                     };
244
245                     SqlHelper.ExecuteNonQuery(Application["DSN"].ToString(), "prc_xoem_stor_nominate_qtr_mark", paraList);
246                      mkCount++;
247                 }
248
249             }
250
251             if (mkCount ==0)
252             {
253                 string msg = "Please select at lease one item to Mark !";
254                 PageAlert(msg);
255             }
256             else
257             {
258                 string msg = "Successful Mark store is : " + mkCount + " !";
259                 PageAlert(msg);
260             }
261
262             //重新加载数据
263             gridBind();
264
265             bindNextPage(0);
266         }
267         /// <summary>
268         /// 取消标记
269         /// </summary>
270         /// <param name="sender"></param>
271         /// <param name="e"></param>
272         protected void btnUnmark_Click(object sender, EventArgs e)
273         {
274             int unMkCount = 0;
275
276             for (int i = 0; i < GridMain.Items.Count; i++)
277             {
278                 CheckBox CB = (CheckBox)GridMain.Items[i].FindControl("chkSelected");
279                 if (CB.Checked==true)
280                 {
281                     SqlParameter[] paraList = new SqlParameter[] {
282                              new SqlParameter("@yyyyqq",ddlQuarter.SelectedValue),
283                              new SqlParameter("@wwid",ViewState["WWID"].ToString()),
284                              new SqlParameter("@stor_id",GridMain.Items[i].Cells[4].Text.Trim()),
285                              new SqlParameter("@co_id",GridMain.Items[i].Cells[18].Text.Trim())
286                     };
287
288                     SqlHelper.ExecuteNonQuery(Application["DSN"].ToString(), "prc_xoem_stor_nominate_qtr_unmark", paraList);
289                     unMkCount++;
290                 }
291             }
292             if (unMkCount==0)
293             {
294                 string msg = "Please select at lease one item to Unmark !";
295                 PageAlert(msg);
296             }
297             else
298             {
299                 string msg = "Successful unmark store is : " + unMkCount + " !";
300                 PageAlert(msg);
301             }
302             //重新加载数据
303             gridBind();
304
305             bindNextPage(0);
306
307         }
308
309         protected void btnSearch_Click(object sender, EventArgs e)
310         {
311             gridBind();
312
313             bindNextPage(0);
314
315             if (ViewState["actionFlag"].ToString() == "1")
316             {
317                 this.btnMark.Enabled = true;
318                 this.btnUnmark.Enabled = true;
319             }
320             else
321             {
322                 this.btnMark.Enabled = false;
323                 this.btnUnmark.Enabled = false;
324             }
325         }
326
327         protected void GridMain_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
328         {
329             //GridMain.CurrentPageIndex = e.NewPageIndex;
330             bindNextPage(e.NewPageIndex);
331         }
332
333         /// <summary>
334         /// 标记Style设置
335         /// </summary>
336         private void NotedStyle()
337         {
338             for (int i = 0; i < GridMain.Items.Count; i++)
339             {
340                 if (GridMain.Items[i].Cells[13].Text.Trim() == "覆盖")
341                 {
342                     GridMain.Items[i].Cells[13].ForeColor = System.Drawing.Color.Red;
343                 }
344                 if (GridMain.Items[i].Cells[24].Text.Trim() == "覆盖")
345                 {
346                     GridMain.Items[i].Cells[24].ForeColor = System.Drawing.Color.Red;
347                 }
348             }
349         }
350
351         /// <summary>
352         /// 提示代码
353         /// </summary>
354         /// <param name="strMsg"></param>
355         private void PageAlert(string strMsg)
356         {
357             this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Alter", "<script language=javascript>alert(‘" + strMsg + "‘);</script>");
358         }
359
360         protected void ddlQuarter_SelectedIndexChanged(object sender, EventArgs e)
361         {
362             this.txtQuarter.Text = ddlQuarter.SelectedValue;
363         }
364
365
366         protected void GridMain_SelectedIndexChanged(object sender, EventArgs e)
367         {
368
369         }
370
371     }
372 }

				
时间: 2024-11-05 06:25:20

c#大圣之路笔记——c# DataGrid checkbox 操作的相关文章

c#大圣之路笔记——c# 从DataGrid中导出数据 Session

1 ///前端代码 2 <tr> 3 <td align="right"> 4 <asp:Button ID="btnExport" runat="server" Text="导出错误数据" CssClass="fieldButton" OnClick="btnExport_Click" style=" height:24px; width:100

SQL大圣之路笔记——SQL 创建索引 index

1 --创建索引的标准:根据实际的sql语句进行分析,’列’出现在where中的次数较多,时间损耗较大,则为这个‘列’建立索引, 2 3 --注意:不是越多越好,因为没建立一个‘列’索引,都要排序存储一次,会让数据库文件变大 4 5 6 --创建索引 7 create index index_name 8 on 表名(列名)

SQL大圣之路笔记——SQL学习笔记

1.复习->自连接 针对于什么结构的表做自连接 关系列引用本表的主键列信息 这种表不是单一的含义->外连接 left join right join full join->case子句 必须出现在select语句中 完成选择功能->常用全局变量:@@identity,@@error->over子句:结合编号.聚合使用 sum(ocount) over() 开窗函数:将多行数据进行划区 over(partition by 列名 order by 列名) rank() row_n

c#大圣之路笔记——c#通过页面把excel中的数据导入到DB中(全部)

1 ///html 2 3 4 <html xmlns="http://www.w3.org/1999/xhtml"> 5 <head id="Head1" runat="server"> 6 <title> 批量修改</title> 7 <link href="../css/main.css" rel="stylesheet" type="t

SQL大圣之路笔记——SQL 获取excel中的数据

1 select 2 --case (isnumeric(CMF_No)) when 1 then Convert(decimal(18,0),CMF_No) 3 --else Convert(nvarchar(255),CMF_No) end as CMF_No,Disti_Name, 4 --case (isnumeric(Disti_Invoice_Num)) when 1 then Convert(decimal(18,0),Disti_Invoice_Num) else 'sss' e

c#大圣之路笔记——TFS解决离职人员文件签出遗留签入问题

方法二: 使用 MSBuild Sidekick MSBuild Sidekick 是VS的一个第三方工具套件,使用此工具的TFS账号必须要有一定的权限,以下简单说明使用方法. 首先至 http://www.attrice.info/downloads/index.htm 下载 Sidekick 安装档,关闭VS安装此工具,安装完成后在VS工具列的「工具」标签中会多出一个「Team Foundation Sidekick」选项,选择到该选项内的「Status Sidekick」选项. 选择后会跳

SQL大圣之路笔记——把数据库中表里的数据导出成Excel(Copy时,会因分隔符问题导致许多数据存放在一个单元格中)

1.选中DB, 右击选择"Tasks",选中"Export Data" 点击. 2.点击"Next", Authentication 选择使用 "Windows 用户名认证" or "SQL Server 用户名,密码认证",点击"Next".    3.保存文件格式:"Excel", 选择保存文件的路径.Excel 版本,点击"Next".-&g

c#大圣之路笔记——c#编程之@的3种作用

1.忽略转义字符例如string fileName = "D:\文本文件\text.txt";使用@后string fileName = @"D:文本文件\text.txt"; 2.让字符串跨行例如string strSQL = "SELECT * FROM HumanResources.Employee AS e"    " INNER JOIN Person.Contact AS c"    " ON e.Con

SQL大圣之路笔记——把Excel中的数据通过Access导入到DataBase中

把Excel中的数据通过Access导入到DataBase中 1.打开Access ,点击“EXTERNAL DATA",选择上传”excel",选中需要导入的excel,点击ok. 2.选择excel中需要上传数据的sheet,点击”next",再点击“next”,选择列明,更改 Data Type (Short Text类型导入后会成为nvarchar);点击“next”,再点击“next” ,设定导入DB之后的表名,点击“finish”. 3.右击表名,点击“Expor