Retrieving dropdownlist gridview rowupdating event
Basically, the scenario I have is that I have a foreign key column in my Grid View that I want to show as a Drop Down List of values.
In this article, I am going to explain how to manipulate data using Grid View control.
This article scope is limited to Updating and Deleting records using Grid View and I am not using any readymade Data controls for that but manually writing all event methods.
This will make sure that Bind Data() method will not fire when you are going to edit, update or delete the record.
In Bind Data() method, I am getting the data from database using Sql objects and specifying the Data Source property of the Grid View to the Pages Data table of the Data Set.
Everyone using Row Editing event handler by using findcontrol method and editindex number. Name Brand" & " FROM Product P, Brand B" & " WHERE P. ID" Dim s Constr As String = Configuration Manager. Connection String Using conn As New Sql Connection(s Constr) Using comm As New Sql Command(SQL, conn) conn. Data Bind() End Sub 0 Then Dim cbo Brand As Drop Down List = Direct Cast(e. Find Control("cbo Brand"), Drop Down List) Dim dt As Data Table Dim SQL As [String] = "SELECT * FROM Brand" Dim s Constr As String = Configuration Manager. Connection String Using conn As New Sql Connection(s Constr) Using comm As New Sql Command(SQL, conn) conn.
That is, get the value from the dropdownlist, and set it in the event.
In practical scenario you should use your existing architecture to populate and update the data.I have specified Data Key Names as Auto ID, the primary key of the database table.Then I have several methods attached with following events Get video of hundreds of ASP. On Row Editing - Edit Record On Row Cancel Edit - Cancel Record On Row Updating - Update Record On Row Deleting - Delete Record As I set Auto Generate Columns property to false so I am going to manually write the fields name that I need to appear in the way I want.The code below shows me the values in the Drop Down List, but when I update it with the “edit” of the Grid View row, the value does not get saved.Here is the code and what it looks like running: Notice that even though I’m using Bind rather than eval, the value does not stick.So, I guess I should have know the answer to why the following does not work.