Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropdownList on Datagrid

Status
Not open for further replies.

tpr25

MIS
Jul 8, 2004
6
US
Hello,
I am trying to use a dropdownlist bound to a datagrid on ItemType. I have no problem getting the values populated into the lists, but when I try to create the command OnSelectedIndexChange for the dropdownlist i get the error "BC30408: Method 'Public Sub Update(sender As Object, E As System.Web.UI.WebControls.DataGridCommandEventArgs)' does not have the same signature as delegate 'Delegate Sub EventHandler(sender As Object, e As System.EventArgs)'."

I understand why I am getting that error; because the command is not part of the datagrid commands. Here is the code
Code:
    Public Sub Update(ByVal sender As System.Object, ByVal E As DataGridCommandEventArgs)

        Dim Orgddl As DropDownList = E.Item.FindControl("OrganismDDL")

        Dim cnn As SqlConnection
        Dim cmd As SqlCommand
        cnn = New SqlConnection(ConfigurationSettings.AppSettings("theConnection"))
        cnn.Open()
        Dim sSql As String
        Dim x1 As String
        x1 = CentralGrid.DataKeys.Item(E.Item.ItemIndex)

        sSql = "Update Central_Line "
        sSql += "SET "
        sSql += "Infection = '" & OrgDdl.SelectedItem.Text & "' "
        sSql += "Where Rec_No = " + x1

        cmd = New SqlCommand(sSql, cnn)
        cmd.ExecuteNonQuery()

        LoadGrid()

    End Sub

How to I call a command that will get the value from the dropdownlist and write it to the database?

Any help is appreciated.
Thank you
 
You need to use the Datagrid.Update command.


--
Not until I became a Network Administrator did the error message "See your Network Administrator for assistance" become petrifying.
 
Hi,

In general, you would not want to run to your database every time you change data in your datagrid. It would be better if you update everything at one time at the end of the page with a "Save" button. In the save method you can then spin through the data and make the changes accordingly.

If you really need to make a change every time the dropdown changes, you may want to look at a repeater instead of a datagrid. It has been a while but I think that you can better attatch to the events in it.

hth

bassguy

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top