This is a migrated thread and some comments may be shown as answers.

How to extract multiselect values from listbox during updating event

1 Answer 80 Views
This is a migrated thread and some comments may be shown as answers.
William Corry
Top achievements
Rank 1
William Corry asked on 20 Feb 2009, 04:11 PM
I am trying to use the update command capability of the SqlDataSource control.  I only have two parameters to pass to the command.  When both parameters (@key_id, @value) are the default value of the controls used to get them the procedure works correctly.  The difficult comes when I want to use a multiselect list box to collect correct values for the @value parameter.  The approach I am trying to take is to use the updating event of the SqlDataSource to get the values for the listbox. The code I have is shown below.  

This approach works when I set the code in newcodeblock  to:   GetAllValues = "blue"      but obviously with the wrong value. 

What I need to know is which parameter (sender or e) can I pass to the function GetAllParmeters to extract a reference to the mutliselect listbox so that I can get the selected values and assemble them into their correct form (e.g. a concatonated string).

If a reference to the listbox cannot be obtained at this point, is there a way of getting the correct values another way?


Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating



"@value").Value = GetAllValues(sender)  


Private Function GetAllValues(ByVal sender As Object) As System.String  
    'do something to set a reference to the listbox so selected values can be concatonated

End Function




1 Answer, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 23 Feb 2009, 10:01 AM
Hi William,

I guess you are using FormTemplate for editing the record and need to get the reference to ListBox placed in FormTemplate. Try the following code snippet for accessing the ListBox control.

     <asp:ListBox ID="ListBox1" runat="server"

Private Function GetAllValues(ByVal sender As ObjectAs String 
    For Each item As GridEditableItem In RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem) 
        If item.IsInEditMode Then 
            Dim lbox As ListBox = DirectCast(item.FindControl("ListBox1"), ListBox) 'Get the ListBox control in FormTemplate    
        End If 
End Function 

Asked by
William Corry
Top achievements
Rank 1
Answers by
Top achievements
Rank 2
Share this question