Tabloo Quijico
Tabloo Quijico

Reputation: 700

DropDownList within GridView - update row with OnSelectedIndexChanged

I have a list of items in a GridView, with one column I'd like editable through a DropDownList.

I do not wish to put the GridView into 'edit' mode or have any 'confirm/update/save' buttons.. I just want autopostback on the DDL, and an OnSelectedIndexChangedevent to update the row.

Problem is, from my OnSelectedIndexChangedevent within the DDL, although I can see the new value to save, I can't discover the row to update from the GridView.

Can anyone see how I can achieve what I wish? Other than perhaps storing the row id within the DDL? Maybe turn it around so the GridView's events are called?

I guess this kind of questions comes from starting with ms-access :)

Cheers!

Upvotes: 0

Views: 2642

Answers (2)

DeanMc
DeanMc

Reputation: 11

I use this, and it works well.

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As System.EventArgs)
    Dim TheRowIndex As Integer = sender.Parent.Parent.RowIndex
    Gridview1.UpdateRow(TheRowIndex, False)
    Gridview1.DataBind()
End Sub

You can also use this same code for CheckBox etc.

Cheers

Dean

Upvotes: 1

Brian Mains
Brian Mains

Reputation: 50728

Typically, you'd rebind the GridView with the data again to do this. You could also try looping up to the GridViewRow by accessing the DropDownList's Parent property; if you do enough parent references (ddl.Parent.Parent), eventually, one of those parent references is the GridViewRow.

HTH.

Upvotes: 1

Related Questions