Update a Database Using Dropdownlist in ASP VB.Net
-
Hello all, First off I am using VB.net I have a dropdown list in the Item template. I would like the user to select a value and update the database without clicking an update button. Here is the Code for the DDL
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="provider"
DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged = "ddl_SelectedChange"
SelectedValue='<%# Bind("provider") %>'>
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>here is my Behind code I am not sure what to put after the Dim statement
Protected Sub ddl_SelectedChange(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl = DirectCast(sender, DropDownList)Any help would be greatly appreciated
-
Hello all, First off I am using VB.net I have a dropdown list in the Item template. I would like the user to select a value and update the database without clicking an update button. Here is the Code for the DDL
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="provider"
DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged = "ddl_SelectedChange"
SelectedValue='<%# Bind("provider") %>'>
<asp:ListItem Value=""></asp:ListItem>
</asp:DropDownList>here is my Behind code I am not sure what to put after the Dim statement
Protected Sub ddl_SelectedChange(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ddl = DirectCast(sender, DropDownList)Any help would be greatly appreciated
Where is the rest of the code behind?? or do you want us to help you in writing that???
-
Where is the rest of the code behind?? or do you want us to help you in writing that???
Yes I am asking for hep is wrting that. Thanks,
-
Yes I am asking for hep is wrting that. Thanks,
* Now that you have the drop down list object, you can get the selected value/text. * You need to determine the row from which the event was fired and get the id. - Simple means would be to associate the primary key data to the dropdown using attributes. You can use these data to save the info to the database. HTH!
-
* Now that you have the drop down list object, you can get the selected value/text. * You need to determine the row from which the event was fired and get the id. - Simple means would be to associate the primary key data to the dropdown using attributes. You can use these data to save the info to the database. HTH!
<asp:DropDownList ID="provider" runat="server" DataSourceID="dr" DataTextField="provider" DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged="dd_OnSelectedIndexChanged" SelectedValue='<%# Bind("provider") %>'> <asp:ListItem Value=""></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="provider" runat="server" DataSourceID="dr" DataTextField="provider" DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged="dd_OnSelectedIndexChanged" SelectedValue='<%# Bind("provider") %>'> <asp:ListItem Value=""></asp:ListItem> </asp:DropDownList>
Here is the Behind CodeProtected Sub dd_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
'*******************************************************
'*This will get the dropdownlist which has been clicked*
'*******************************************************
Dim ddl As DropDownList
ddl = DirectCast(sender, DropDownList)
'***********************************************************************
'*The row will be the currently selected row from which the dropdownlist*
'*was clicked *
'***********************************************************************
Dim row As GridViewRow = DirectCast(ddl.NamingContainer, GridViewRow)
'******************************
'*Get the datakey for that row*
'******************************
Dim DataKey As String = GridView1.DataKeys(row.RowIndex).Values("IEN").ToString()
'**********************
'*Define Data Objects *
'**********************
Dim conn As SqlConnection
Dim comm As SqlCommand'\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* '\*Read the connectionstring from we.config\* '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("ER\_BloodHoundConnectionString").ConnectionString '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* '\*Initialize Connection\* '\*\*\*\*\*\*\*\*\*\*\*
-
<asp:DropDownList ID="provider" runat="server" DataSourceID="dr" DataTextField="provider" DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged="dd_OnSelectedIndexChanged" SelectedValue='<%# Bind("provider") %>'> <asp:ListItem Value=""></asp:ListItem> </asp:DropDownList> <asp:DropDownList ID="provider" runat="server" DataSourceID="dr" DataTextField="provider" DataValueField="provider" AutoPostBack="True" AppendDataboundItems="true" OnSelectedIndexChanged="dd_OnSelectedIndexChanged" SelectedValue='<%# Bind("provider") %>'> <asp:ListItem Value=""></asp:ListItem> </asp:DropDownList>
Here is the Behind CodeProtected Sub dd_OnSelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
'*******************************************************
'*This will get the dropdownlist which has been clicked*
'*******************************************************
Dim ddl As DropDownList
ddl = DirectCast(sender, DropDownList)
'***********************************************************************
'*The row will be the currently selected row from which the dropdownlist*
'*was clicked *
'***********************************************************************
Dim row As GridViewRow = DirectCast(ddl.NamingContainer, GridViewRow)
'******************************
'*Get the datakey for that row*
'******************************
Dim DataKey As String = GridView1.DataKeys(row.RowIndex).Values("IEN").ToString()
'**********************
'*Define Data Objects *
'**********************
Dim conn As SqlConnection
Dim comm As SqlCommand'\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* '\*Read the connectionstring from we.config\* '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("ER\_BloodHoundConnectionString").ConnectionString '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* '\*Initialize Connection\* '\*\*\*\*\*\*\*\*\*\*\*
Thanks all. Problem solved. See previous post.:cool: