473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

edit gridview without using SqlDataSource

I am creating gridview using connectionstring. i am passing different queries to bind grid as per condition. Now the problem I am facing on editing the grid. I am not able to use boundfield or template field because data coming from different table as per condition and number of field are also different.

I can edit the data with the following code:

Expand|Select|Wrap|Line Numbers
  1.  Public Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
  2.         GridView1.EditIndex = e.NewEditIndex
  3.         Call LoadGrid()
  4.  
  5.         Dim f1 As String = GridView1.Rows(e.NewEditIndex).Cells(1).Text
  6.         Dim f2 As String = GridView1.Rows(e.NewEditIndex).Cells(2).Text
  7.         Dim f3 As String = GridView1.Rows(e.NewEditIndex).Cells(3).Text
  8.         lbl1.Text = f1
  9.         lbl2.Text = f2
  10.         lbl3.Text = f3
  11.  
  12.               ''Dim dc As TextBox = GridView1.Rows(e.NewEditIndex).Cells(1).FindControl("bdistcode")
  13.         ''lblDn.Text = dc.Text
  14.     End Sub
  15.  
  16.     Public Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
  17.         If (Session("sid").ToString() = "d" Or Session("sid").ToString() = "s" Or Session("sid").ToString() = "b") Then
  18.             Dim f1 As String = GridView1.Rows(e.RowIndex).Cells(1).Text
  19.             Dim f2 As String = GridView1.Rows(e.RowIndex).Cells(2).Text
  20.             Dim f3 As String = GridView1.Rows(e.RowIndex).Cells(3).Text
  21.                      Select Case (Session("sid").ToString())
  22.                 Case "d"
  23.                     constr = "update D set dc=@f1,dn_h=@f2 where dn=@f3"
  24.                 Case "s"
  25.                     constr = "update sd set sd_c=@f1,sd_nm=@f2 where id=@f3"
  26.                 Case "b"
  27.                     constr = "update bl set blc=@f1,bln=@f2 where id=@f3"
  28.             End Select
  29.             cmd = New SqlCommand(constr, con)
  30.             Try
  31.                 If con.State = ConnectionState.Closed Then con.Open()
  32.  
  33.                 cmd.Parameters.Clear()
  34.                 cmd.Parameters.Add(New SqlParameter("@f1", SqlDbType.NVarChar)).Value = f1.ToString()
  35.                 cmd.Parameters.Add(New SqlParameter("@f2", SqlDbType.NVarChar)).Value = f2.ToString()
  36.                 If (Session("sid").ToString() = "d") Then
  37.                     cmd.Parameters.Add(New SqlParameter("@f3", SqlDbType.VarChar)).Value = f3.ToString()
  38.                 Else
  39.                     cmd.Parameters.Add(New SqlParameter("@f3", SqlDbType.Int)).Value = Convert.ToInt32(f3)
  40.                 End If
  41.  
  42.                 Dim rowno As Integer = cmd.ExecuteNonQuery()
  43.             Catch ex As Exception
  44.                 lblMessage.Text = lblMessage.Text & "Error" & ex.Message & "Field Value f1="
  45.                 If con.State = ConnectionState.Open Then con.Close()
  46.             Finally
  47.                 If con.State = ConnectionState.Open Then con.Close()
  48.             End Try
  49.  
  50.             'lblMessage.Text = "Record Updated Successfully"
  51.             'lblMessage.Visible = True
  52.  
  53.             GridView1.EditIndex = -1
  54.             Call LoadGrid()
  55.         End If
  56.  
  57.  
  58.     End Sub
May 31 '10 #1
1 3162
Frinavale
9,735 Expert Mod 8TB
I think, if I were you, to keep things simple (KISS), I would use 1 GridView per data source.

-Frinny
May 31 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. ...
0
by: Will | last post by:
I have searched and solutions that I have found are not working, I have a datagrid that will be updating a mysql db. Now I have a drop down that has a static collection but is dynamically selected...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
3
by: phanimadhav | last post by:
hi this is sudheer, i am new one of this ASP.NET .i have one problem,i am using gridview control i know how to place the dropdownlistbox in gridview control.in my gridveiw control have contain...
3
by: mathewgk80 | last post by:
Hi all, I would like to connect gridview with database without using sql datasource.. I am using sql server and c#.net.. Please help me.. regards, Mathew.
5
by: Luqman | last post by:
I added new rows to the GridView with the following code. I am using SqlDataSource and Sql Server 2000 Northwind Database Customers table. Dim sqlarg As New DataSourceSelectArguments Dim dv...
1
by: sweatha | last post by:
Hi I connected SQLDataSource in GridView by using coding <asp:GridView ID="Search_GridView" runat="server" Style="z-index: 100; left: 2px; position: absolute; top: 270px"...
1
by: senthilcyr | last post by:
hi, How to delete a row from gridview without using database. Thanks, Senthilvelan.N
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
28
by: AnagJohari | last post by:
If I want to access the method in which we define update query, how can I access that method on aspx page & update the data in a grid view without direct use of an query on aspx page under sql data...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.