diff --git "a/C#/GridView-\345\226\256\345\210\227\351\233\231\345\210\227\351\241\217\350\211\262\344\270\215\345\220\214.txt" "b/C#/GridView-\345\226\256\345\210\227\351\233\231\345\210\227\351\241\217\350\211\262\344\270\215\345\220\214.txt" new file mode 100644 index 0000000..270de5a --- /dev/null +++ "b/C#/GridView-\345\226\256\345\210\227\351\233\231\345\210\227\351\241\217\350\211\262\344\270\215\345\220\214.txt" @@ -0,0 +1,22 @@ +protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) + { + if (e.Row.RowIndex != -1) + { + + //自動變色機制 + if (e.Row.RowIndex % 2 == 1) + { + //單數資料列 + e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#FFFFFF"); + e.Row.Attributes.Add("onmouseout", "onmouseChangeRowColor(this,true,false);"); + e.Row.Attributes.Add("onmouseover", "onmouseChangeRowColor(this,true,true);"); + } + else + { + //雙數資料列 + e.Row.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#EFF3FB"); + e.Row.Attributes.Add("onmouseout", "onmouseChangeRowColor(this,false,false);"); + e.Row.Attributes.Add("onmouseover", "onmouseChangeRowColor(this,false,true);"); + } + } + } \ No newline at end of file diff --git "a/C#/GridView-\346\250\243\346\235\277.txt" "b/C#/GridView-\346\250\243\346\235\277.txt" new file mode 100644 index 0000000..e49f275 --- /dev/null +++ "b/C#/GridView-\346\250\243\346\235\277.txt" @@ -0,0 +1,62 @@ +雙向繫結 Bind() +單向繫結 Eval() + + +[textbox] +1.add template col +2.edit template : 拉textbox +3.在textbox binding : DataBinder.Eval(Container, "DataItem.操盤人") + +[checkbox] +1.add template col +2.edit template : 拉check +3.在check.checked set (Eval("chk2").ToString()=="1") + +[修改-c1webgrid] + +1.add template col +2.edit template : 拉LinkButton +3.set commandName +4. +this.C1WebGridList.DeleteCommand += new C1.Web.C1WebGrid.C1CommandEventHandler(this.C1WebGridList_DeleteCommand); + private void C1WebGridList_DeleteCommand(object source, C1.Web.C1WebGrid.C1CommandEventArgs e) + { + ............................. + } + +[修改-Gridview] +1.add template col +2.edit template : 拉LinkButton +3.set commandName +4.程式碼 + + protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) + { + GridView tmp = GridView1;// (GridView)source; + int pk_key = ((GridViewRow)((LinkButton)e.CommandSource).NamingContainer).RowIndex; + + string sID = tmp.Rows[pk_key].Cells[2].Text.Trim(); + Response.Redirect("data_input_modify.aspx?mode=insert&input_id=" + sID ); + } + +QA 如何拿viisble=false的cell值 +不可以直接visible=false,要bind完再visible + protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) + { + if (e.Row.RowType == DataControlRowType.Header || e.Row.RowType == DataControlRowType.DataRow) + { + e.Row.Cells[2].Visible = false;//要隱藏的欄位 + } + } + +https://dotblogs.com.tw/eason.yen/2011/01/31/21164 + + +[刪除] + + + + + + + diff --git "a/C#/GridView\344\275\277\347\224\250\346\226\271\346\263\225.docx" "b/C#/GridView\344\275\277\347\224\250\346\226\271\346\263\225.docx" new file mode 100644 index 0000000..cbf921f Binary files /dev/null and "b/C#/GridView\344\275\277\347\224\250\346\226\271\346\263\225.docx" differ diff --git "a/C#/ReportView\344\275\277\347\224\250\346\226\271\346\263\225.docx" "b/C#/ReportView\344\275\277\347\224\250\346\226\271\346\263\225.docx" new file mode 100644 index 0000000..c358284 Binary files /dev/null and "b/C#/ReportView\344\275\277\347\224\250\346\226\271\346\263\225.docx" differ diff --git "a/C#/TreeView\347\232\204\344\275\277\347\224\250\346\226\271\345\274\217.docx" "b/C#/TreeView\347\232\204\344\275\277\347\224\250\346\226\271\345\274\217.docx" new file mode 100644 index 0000000..adcbb3c Binary files /dev/null and "b/C#/TreeView\347\232\204\344\275\277\347\224\250\346\226\271\345\274\217.docx" differ diff --git a/C#/gridview-merge.txt b/C#/gridview-merge.txt new file mode 100644 index 0000000..6e59d44 --- /dev/null +++ b/C#/gridview-merge.txt @@ -0,0 +1,39 @@ +protected void GridView1_PreRender(object sender, EventArgs e) + { + if (isSearch == false) return; + isSearch = false; + + foreach (GridViewRow gvR in this.GridView1.Rows) + { + for (int i = gvR.DataItemIndex + 1; i < this.GridView1.Rows.Count; i++) + { + //與下一列欄位值相等; + if (this.GridView1.Rows[i].Cells[1].Text.Trim() != " ") + { + if (gvR.Cells[1].Text.Trim() == this.GridView1.Rows[i].Cells[1].Text.Trim()) + { + gvR.Cells[1].RowSpan = gvR.Cells[1].RowSpan == 0 ? gvR.Cells[1].RowSpan = 2 : gvR.Cells[1].RowSpan += 1; + this.GridView1.Rows[i].Cells[1].Visible = false; + } + else + { + break; + } + } + } + + for (int i = gvR.DataItemIndex + 1; i < this.GridView1.Rows.Count; i++) + { + //與下一列欄位值相等; + if (gvR.Cells[0].Text.Trim() == this.GridView1.Rows[i].Cells[0].Text.Trim()) + { + gvR.Cells[0].RowSpan = gvR.Cells[0].RowSpan == 0 ? gvR.Cells[0].RowSpan = 2 : gvR.Cells[0].RowSpan += 1; + this.GridView1.Rows[i].Cells[0].Visible = false; + } + else + { + break; + } + } + } + } \ No newline at end of file diff --git a/C#/reader.txt b/C#/reader.txt new file mode 100644 index 0000000..fb79f64 --- /dev/null +++ b/C#/reader.txt @@ -0,0 +1,95 @@ +https://msdn.microsoft.com/zh-tw/library/haa3afyz(v=vs.110).aspx + +需要擷取大量資料時,DataReader 是不錯的選擇,因為資料不會快取至記憶體。 + +用完 DataReader 物件後,請務必呼叫 Close 方法。 +如果您的 Command 包含輸出參數或傳回值,則必須等到 DataReader 關閉後才能使用它們。 +請注意,DataReader 開啟期間,Connection 只能供該 DataReader 使用。 必須等到原始 DataReader 關閉後,才能執行 Connection 的任何命令,包括建立其他 DataReader。 +================== +if (reader.HasRows) + while (reader.Read()) + reader.GetValue(1) +reader.Close(); +====================================== + string cn = " Provider=SAOLEDB;Data Source=DW_IQ_NEW "; + + System.Data.OleDb.OleDbConnection con = null; + con = new System.Data.OleDb.OleDbConnection(cn); + + con.Open(); + System.Data.OleDb.OleDbCommand command = con.CreateCommand(); + + command.CommandText = @"Select top 10 * from TRADETOOL_FEE"; + + System.Data.OleDb.OleDbDataReader reader = command.ExecuteReader(); + if (reader.HasRows) + { + while (reader.Read()) + { + laCount1.Text += string.Format("{0}\t{1}\t{2}\t{3}\t{4} ", reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4)); + + //Console.WriteLine("{0}\t{1}", reader.GetString(0), reader.GetString(1)); + } + } + reader.Close(); + +====================================== +下列程式碼範例在 DataReader 物件中重複,並從每個資料列傳回兩個資料行。 +C# +static void HasRows(SqlConnection connection) +{ + using (connection) + { + SqlCommand command = new SqlCommand( + "SELECT CategoryID, CategoryName FROM Categories;", + connection); + connection.Open(); + + SqlDataReader reader = command.ExecuteReader(); + + if (reader.HasRows) + { + while (reader.Read()) + { + Console.WriteLine("{0}\t{1}", reader.GetInt32(0), + reader.GetString(1)); + } + } + else + { + Console.WriteLine("No rows found."); + } + reader.Close(); + } +} + +==================== +使用 NextResult 來擷取多個結果集 +如果傳回多個結果集,DataReader 會提供 NextResult 方法依序在結果集中重複。 下列範例顯示 SqlDataReader 使用 ExecuteReader 方法,處理兩個 SELECT 陳述式的結果。 +C#VB +static void RetrieveMultipleResults(SqlConnection connection) +{ + using (connection) + { + SqlCommand command = new SqlCommand( + "SELECT CategoryID, CategoryName FROM dbo.Categories;" + + "SELECT EmployeeID, LastName FROM dbo.Employees", + connection); + connection.Open(); + + SqlDataReader reader = command.ExecuteReader(); + + while (reader.HasRows) + { + Console.WriteLine("\t{0}\t{1}", reader.GetName(0), + reader.GetName(1)); + + while (reader.Read()) + { + Console.WriteLine("\t{0}\t{1}", reader.GetInt32(0), + reader.GetString(1)); + } + reader.NextResult(); + } + } +} \ No newline at end of file