Jump to content
Xtreme .Net Talk

edora

Members
  • Posts

    24
  • Joined

  • Last visited

About edora

  • Birthday 12/15/1981

edora's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hi, I have a problem with filtering here. I have a combo box which is contains the goup name. And I have a datagrid which is contains all the employee contact. What I want is, when I select any group inside the combo box, it will automatically give the result in datagrid with the employee in that particular group. Ok, I think better if I post you my code... Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then BindData() End If (This is the code to get the item in the combo box)*** Dim myConnection As SqlConnection = New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim ds As DataSet = New DataSet Dim adpCust As SqlDataAdapter = New SqlDataAdapter("Select * from tbl_Group", myConnection) adpCust.Fill(dstName, "GroupTable") Dim drRow As DataRow For Each drRow In dstName.Tables("GroupTable").Rows cboGroup.Items.Add(drRow("Name")) Next (This is the code to display the data in the datagrid) *** Try Dim mycn As New System.Data.SQLClient.SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim myda As New System.Data.SQLClient.SqlDataAdapter("Select System_ID, Name, Mobile_URL from tbl_Contact_List ", mycn) Dim myda1 As New System.Data.SQLClient.SqlDataAdapter("Select System_ID from tbl_Contact_List", mycn) Dim dst As New System.Data.DataSet Dim cb As CheckBox myda.Fill(ds, "Name") myda1.Fill(ds, "System_ID") Dim objbc As BoundColumn Dim dc As DataColumn Dim dt As DataTable For Each dt In ds.Tables Next Catch ex As Exception Response.Write(ex.Message & ex.StackTrace) End Try End Sub Supposingly, as i mention earlier, when I scroll down the combo box and select any of the group category, I will give me the list in datagrid , those who are fall in that group category.. Really need help, Edora
  2. Have solved this problem, thanks for your help anyway robby
  3. Got the right code already...here it is... Private Sub DataGrid2_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid2.EditCommand DataGrid2.EditItemIndex = e.Item.ItemIndex BindData() End Sub Private Sub DataGrid2_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid2.CancelCommand DataGrid2.EditItemIndex = -1 BindData() End Sub Private Sub DataGrid2_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid2.UpdateCommand Dim tbox As TextBox Dim txtSystemId As TextBox Dim System_ID, Group_ID As Integer Dim Name, Mobile_URL As String txtSystemId = e.Item.Cells(2).Controls(0) tbox = e.Item.Cells(3).Controls(0) Name = tbox.Text tbox = e.Item.Cells(4).Controls(0) Mobile_URL = tbox.Text System_ID = txtSystemId.Text Dim sql As String = "UPDATE tbl_Contact_List SET Name='" & Name & "', Mobile_URL='" & Mobile_URL & "' WHERE System_ID='" & System_ID & "'" Dim conn As New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim comm As New SqlCommand(sql, conn) conn.Open() comm.ExecuteNonQuery() conn.Close() DataGrid2.EditItemIndex = -1 BindData() End Sub
  4. Hi guys, Finally I have the right code. So, this is the code that I have implement. Private Sub DataGrid2_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid2.UpdateCommand Dim tbox As TextBox Dim txtSystemId As TextBox Dim System_ID, Group_ID As Integer Dim Name, Mobile_URL As String txtSystemId = e.Item.Cells(2).Controls(0) tbox = e.Item.Cells(3).Controls(0) Name = tbox.Text tbox = e.Item.Cells(4).Controls(0) Mobile_URL = tbox.Text System_ID = txtSystemId.Text Dim sql As String = "UPDATE tbl_Contact_List SET Name='" & Name & "', Mobile_URL='" & Mobile_URL & "' WHERE System_ID='" & System_ID & "'" Dim conn As New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim comm As New SqlCommand(sql, conn) conn.Open() comm.ExecuteNonQuery() conn.Close() DataGrid2.EditItemIndex = -1 BindData() End Sub
  5. Hi guys, Finally I got it, so this is the sample working code! Private Sub cmdButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdButton.Click Dim a As CheckBox For Each myDataGridItem In DataGrid2.Items a = myDataGridItem.FindControl("chkSelection") ' Response.Write(CType(DataGrid2.Items(7).FindControl("chkSelection"), CheckBox).Checked()) If a.Checked Then m_objSMS.delete(myDataGridItem.Cells(2).Text()) End If Next End Sub
  6. Hi guys, Since i cannot get the solution after I tried quite a number of sample, I've decided to change my code. Which is, when i mark the checkbox, and click the button delete outside the datagrid, it will delete the selected rows. Private Sub cmdButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdButton.Click For Each myDataGridItem In DataGrid2.Items If chkSelected.Checked Then (I need some code here to delete the selected row) End If Next End Sub Hoping for help... Thanks
  7. Well, I have change my code like below Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand Dim System_ID As String = CType(e.Item.FindControl("Delete"), LinkButton).Text Dim myTable As DataTable = CType(Session("Contact_ListTable"), DataTable) Dim myRows As DataRowCollection = myTable.Rows Dim thisRow As DataRow = myRows.Find(System_ID) If Not (thisRow Is Nothing) Then myRows.Remove(thisRow) Session("Contact_ListTable") = myTable DataGrid1.DataSource = Session("Contact_ListTable") DataGrid1.DataBind() End Sub but I still get an error which is Line 56: Dim System_ID As String = CType(e.Item.FindControl("Delete"), LinkButton).Text and the error command is Object reference not set to an instance of an object. Anyone could help me to figure out which is wrong? Thanks in advanced, Edora Theo
  8. Sorry, Forgot, When I try to run, I will get this error Cmd.Parameters.Add(New SqlParameter("@System_ID", DataGrid1.DataKeys(CInt(e.Item.ItemIndex)))) WIth the error command - Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Can anyone help me to find our what is the error about? Thanks
  9. Hi guys, I have a datagrid with the delete command in the template. What I want is, whenever I click delete, I should be able to delete that particular row. My code is like below. Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.DeleteCommand Dim strConn As String = "Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;" Dim DeleteCmd As String = "DELETE from COntact_List Where id = @System_ID" Dim MyConn As New SqlConnection(strConn) Dim Cmd As New SqlCommand(DeleteCmd, MyConn) Cmd.Parameters.Add(New SqlParameter("@System_ID", DataGrid1.DataKeys(CInt(e.Item.ItemIndex)))) MyConn.Open() Cmd.ExecuteNonQuery() MyConn.Close() BindData() End Sub Thanks in advanced, Edora Theo
  10. Hi, I have add the quote after & System_ID, now I dont get the error but when i made edit and click on update, it doesnt change anything. Please help me, I dont know why?
  11. Hi, I have remove that particular code from pageload event, but, it gave me a new erorr... Imports System.Data.SqlClient Public Class TestingTesting Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid Protected WithEvents Button1 As System.Web.UI.WebControls.Button 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim mycn As New System.Data.SQLClient.SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim myda As New System.Data.SQLClient.SqlDataAdapter("Select System_ID, Name, Mobile_URL from tbl_Contact_List ", mycn) Dim myda1 As New System.Data.SQLClient.SqlDataAdapter("Select System_ID from tbl_Contact_List", mycn) Dim dst As New System.Data.DataSet Dim cb As CheckBox myda.Fill(dst, "Name") myda.Fill(dst, "System_ID") Dim objbc As BoundColumn Dim dc As DataColumn Dim dt As DataTable For Each dt In dst.Tables Next DataGrid1.DataSource = dst.Tables(0) DataGrid1.DataBind() Catch ex As Exception Response.Write(ex.Message & ex.StackTrace) End Try End Sub Sub BindData() Dim ds As New DataSet Dim mycn As New System.Data.SQLClient.SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim myda As New System.Data.SQLClient.SqlDataAdapter("Select System_ID,Name, Mobile_URL from tbl_Contact_List ", mycn) Dim myda1 As New System.Data.SQLClient.SqlDataAdapter("Select System_ID,Name, Mobile_URL from tbl_Contact_List", mycn) myda1.Fill(ds, "Contact_List") DataGrid1.DataSource = ds DataGrid1.DataBind() End Sub Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand DataGrid1.EditItemIndex = e.Item.ItemIndex DataGrid1.DataBind() End Sub Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand DataGrid1.EditItemIndex = -2 BindData() End Sub Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand Dim tbox As TextBox Dim txtSystemId As TextBox Dim System_ID, Group_ID As Integer Dim Name, Mobile_URL As String txtSystemId = e.Item.Cells(2).Controls(0) tbox = e.Item.Cells(3).Controls(0) Name = tbox.Text tbox = e.Item.Cells(4).Controls(0) Mobile_URL = tbox.Text System_ID = txtSystemId.Text Dim sql As String = "UPDATE tbl_Contact_List SET Name='" & Name & "' , Mobile_URL='" & Mobile_URL & "' WHERE System_ID='" & System_ID Dim conn As New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim comm As New SqlCommand(sql, conn) conn.Open() comm.ExecuteNonQuery() conn.Close() DataGrid1.EditItemIndex = -1 BindData() End Sub End Class ****** The error occured here.... comm.ExecuteNonQuery() with the error command ( Unclosed quotation mark before the character string '160'. Line 1: Incorrect syntax near '160'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Unclosed quotation mark before the character string '160'. Line 1: Incorrect syntax near '160'. Source Error: Line 79: Line 80: conn.Open() Line 81: comm.ExecuteNonQuery() Line 82: conn.Close() Line 83: Hope you can help me to solve this. Thanks in advanced, Edora Theo
  12. Hi bungpeng, I have solved my 'edit' problem but another problem has occured which is UPDATE. If you would like to help me solve my problem, please find my other forum "UPDATE datagrid" because my code was there. Just coudnt figure out what was wrong. Thanks in advanced, Edora
  13. Well, I am not sure about that. Here my is the code. Here is my full code. Imports System.Data.SqlClient Public Class TestingTesting Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid Protected WithEvents Button1 As System.Web.UI.WebControls.Button 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not Page.IsPostBack Then BindData() End If Try Dim mycn As New System.Data.SQLClient.SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim myda As New System.Data.SQLClient.SqlDataAdapter("Select System_ID, Name, Mobile_URL from tbl_Contact_List ", mycn) Dim myda1 As New System.Data.SQLClient.SqlDataAdapter("Select System_ID from tbl_Contact_List", mycn) Dim dst As New System.Data.DataSet Dim cb As CheckBox myda.Fill(dst, "Name") myda.Fill(dst, "System_ID") Dim objbc As BoundColumn Dim dc As DataColumn Dim dt As DataTable For Each dt In dst.Tables Next DataGrid1.DataSource = dst.Tables(0) DataGrid1.DataBind() Catch ex As Exception Response.Write(ex.Message & ex.StackTrace) End Try End Sub Sub BindData() Dim ds As New DataSet Dim mycn As New System.Data.SQLClient.SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim myda As New System.Data.SQLClient.SqlDataAdapter("Select System_ID,Name, Mobile_URL from tbl_Contact_List ", mycn) Dim myda1 As New System.Data.SQLClient.SqlDataAdapter("Select System_ID,Name, Mobile_URL from tbl_Contact_List", mycn) myda1.Fill(ds, "Contact_List") DataGrid1.DataSource = ds DataGrid1.DataBind() End Sub Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand DataGrid1.EditItemIndex = e.Item.ItemIndex DataGrid1.DataBind() End Sub Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.CancelCommand DataGrid1.EditItemIndex = -2 BindData() End Sub Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand Dim tbox As TextBox Dim txtSystemId As TextBox Dim System_ID, Group_ID As Integer Dim Name, Mobile_URL As String txtSystemId = e.Item.Cells(2).Controls(0) tbox = e.Item.Cells(3).Controls(0) Name = tbox.Text tbox = e.Item.Cells(4).Controls(0) Mobile_URL = tbox.Text System_ID = txtSystemId.Text Dim sql As String = "UPDATE tbl_Contact_List SET Name='" & Name & "' , Mobile_URL='" & Mobile_URL & "' WHERE System_ID='" & System_ID & "'" Dim conn As New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim comm As New SqlCommand(sql, conn) conn.Open() comm.ExecuteNonQuery() conn.Close() DataGrid1.EditItemIndex = -1 BindData() End Sub End Class P/s Really need helps, because it was quiet some time i am stuck on this problem. Thanks in advanced, Edora
  14. Hi guys, I would am using below code for UPDATE in database using datagrid. Even though I have the correct System_ID, Name and Mobile_URL, but when I try to key in new data, and UPDATE, It wont update my datagrid and also datagase as well. I can't see the wrong thing in my code, could anyone find out what are the bug in my code? Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand Dim tbox As TextBox Dim txtSystemId As TextBox Dim System_ID, Group_ID As Integer Dim Name, Mobile_URL As String txtSystemId = e.Item.Cells(1).Controls(0) tbox = e.Item.Cells(2).Controls(0) Name = tbox.Text tbox = e.Item.Cells(3).Controls(0) Mobile_URL = tbox.Text System_ID = txtSystemId.Text Dim sql As String = "UPDATE tbl_Contact_List SET Name='" & Name & "' , Mobile_URL='" & Mobile_URL & "' WHERE System_ID='" & System_ID & "'" Dim conn As New SqlConnection("Data Source=isdc01;Initial Catalog=Internet_SMS;user id=sa;pwd=;") Dim comm As New SqlCommand(sql, conn) conn.Open() comm.ExecuteNonQuery() conn.Close() DataGrid1.EditItemIndex = -1 BindData() End Sub Thanks in advanced! Edora Theo
  15. Hi guys, Anyone could help me check my code below. It seems all correct but when I run my datagrid, and CLICK Edit, nothing happend at all. Thanks in advanced, Edora Public Sub edit(ByVal s As Object, ByVal e As DataGridCommandEventArgs) DataGrid2.EditItemIndex = e.Item.ItemIndex Load_Data() End Sub datagrid.bmp
×
×
  • Create New...