Posts

Showing posts from June, 2011

Tip!!! อ้างอิง Rows ใน GridView จาก Event of TemplateField

สาเหตุ... จากข้อมูลใน GridView ที่มี TemplateField เป็น Checkbox และต้องการติ๊ก Checkbox เพื่อต้องการ Summary ยอดเงินรวมแสดงให้ผู้ใช้งานเห็น วิธีการเขียนโปรแกรม... จากวิธีการเดิมๆคือใช้วิธีการวนลูปเพื่อเช็คว่า Checkbox ไหนมีการติ๊กให้ทำการรวมค่าเพื่อแสดงข้อมูล แต่ปัจจุบันมีวิธีการใหม่มานำเสนอคือ Protected Sub chk_CheckedChanged( ByVal sender As Object , ByVal e As System.EventArgs)      Dim chk As CheckBox = CType(sender, CheckBox)   Dim dg_row As GridViewRow = CType(chk.NamingContainer, GridViewRow)   Dim dg_row_index As Integer = dg_row.RowIndex   lbl_SumTotal.Text = gv.Rows(dg_row_index).Cells(7).Text End Sub

Excel (.xls) Sheet To DataSet

1. Import NameSpace Imports System.Data Imports System.Data.Oledb 2. Development Dim myDataset As New DataSet() ''You can also use the Excel ODBC driver I believe - didn''t try though Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ "Data Source=D:\MyXls\MyExcelDB.xls;" & _ "Extended Properties=""Excel 8.0;""" ''You must use the $ after the object you reference in the spreadsheet (## Table Name is ExcelTest ##) Dim myData As New OledbDataAdapter("SELECT * FROM [Sheet1$]", strConn) myData.TableMappings.Add("Table", "ExcelTest") myData.Fill(myDataset) DataGrid1.DataSource = myDataset.Tables(0).DefaultView DataGrid1.DataBind()