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
Grid
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

 

    e.Command.Parameters(

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

 

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
newcodeblock

End Function

 

 

 



1 Answer, 1 is accepted

Sort by
0
Shinu
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.

ASPX:
<FormTemplate> 
     <asp:ListBox ID="ListBox1" runat="server"
     </asp:ListBox> 
</FormTemplate> 

VB:
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 
    Next 
End Function 

Thanks,
Shinu.
Tags
Grid
Asked by
William Corry
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or