Retrieving radiobuttonlist from datagrid

  • Thread starter sona Rampall via .NET 247
  • Start date
S

sona Rampall via .NET 247

I am binding a radiobuttonlist to a datagrid on the ItemDataBound event. See code:

Sub dtgAccesSite_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dtgAccesSite.ItemDataBound
Dim radAcces As New RadioButtonList

radAcces.Items.Insert(0, "Oui")
radAcces.Items.Insert(1, "Non")

radAcces.Items(1).Selected = True
radAcces.Items(0).Selected = False
e.Item.Cells(3).Controls.Add(radAcces)
End Sub

And I'm trying to retrieve the radiobuttonlist value on the Button_click event e.g. Save Button found outside the datagrid. See code:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim i As Integer
Dim _item As DataGridItem

For i = 0 To dtgAccesSite.Items.Count - 1
_item = dtgAccesSite.Items(i)
Dim Usr_radio As RadioButtonList = _item.FindControl("radAcces")
Usr_radio.SelectedItem.Value
Next

End Sub

It cannot find the RadioButtonList "radAcces" anywhere in the datagrid - can anyone help - this code will work using textbox, labels, etc.
 
S

Shailesh Jannu

If you are creating the radio button dynamically in
databound event.. Then you should make sure that the grid
is bound before the viewstate is loaded.
Please check this article. Might be helpful.

http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridSe
rverControl.asp


-----Original Message-----
I am binding a radiobuttonlist to a datagrid on the ItemDataBound event. See code:

Sub dtgAccesSite_ItemDataBound(ByVal sender As Object,
ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
dtgAccesSite.ItemDataBound
Dim radAcces As New RadioButtonList

radAcces.Items.Insert(0, "Oui")
radAcces.Items.Insert(1, "Non")

radAcces.Items(1).Selected = True
radAcces.Items(0).Selected = False
e.Item.Cells(3).Controls.Add(radAcces)
End Sub

And I'm trying to retrieve the radiobuttonlist value on
the Button_click event e.g. Save Button found outside the
datagrid. See code:
Private Sub btnSave_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSave.Click
Dim i As Integer
Dim _item As DataGridItem

For i = 0 To dtgAccesSite.Items.Count - 1
_item = dtgAccesSite.Items(i)
Dim Usr_radio As RadioButtonList = _item.FindControl("radAcces")
Usr_radio.SelectedItem.Value
Next

End Sub

It cannot find the RadioButtonList "radAcces" anywhere in
the datagrid - can anyone help - this code will work using
textbox, labels, etc.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,242
Latest member
KendrickKo

Latest Threads

Top