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

[Solved] Combobox in RadGrid

3 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DavidA
Top achievements
Rank 1
DavidA asked on 01 Oct 2009, 10:17 AM
Hi,

I have a radgrid with a combobox field. I am following the example set out here:
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/comboingrid/defaultcs.aspx?product=grid

I have changed this example to be driven off code behind. I am trying to also update the backend sql tables from the codebehind by using OnUpdateCommand="RadGridFieldMappings_UpdateCommand". The issue is that I dont know how to get the value to the selected combox item in the code behind to then update the sql tables.  Please help!

Main ASPX page / radgrid code here.
       <telerik:radgrid id="RadGridFieldMappings" runat="server" 
            AutoGenerateColumns"False"  
            AllowSorting="True"  
            AllowPaging="True" 
            OnNeedDataSource="RadGridFieldMappings_NeedDataSource" 
            OnDataBound = "RadGridFieldMappings_DataBound" 
            OnUpdateCommand="RadGridFieldMappings_UpdateCommand" 
            AllowAutomaticUpdates="true" 
            PageSize="15" 
            GridLines="Both" 
            Height="300px" 
           > 
           <MasterTableView ShowFooter="false" DataKeyNames="ID" EditMode="InPlace"
               <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle> 
              <Columns> 
                  <telerik:GridNumericColumn DataField="ID" UniqueName="ID" HeaderText="ID" Visible="false" ReadOnly="True"/> 
                    
                  <telerik:GridBoundColumn UniqueName="ListID" HeaderText="ListID" DataField="ListID" Visible="false" ReadOnly="True"
                     <HeaderStyle Width="40px"></HeaderStyle> 
                    </telerik:GridBoundColumn> 
                                  
                    <telerik:GridBoundColumn UniqueName="ListName"  HeaderText="List Name" DataField="ListName" ReadOnly="True"
                    <HeaderStyle Width="155px"></HeaderStyle> 
                    </telerik:GridBoundColumn> 
                     
                    <telerik:GridBoundColumn UniqueName="FieldName" HeaderText="FieldName" DataField="FieldName" ReadOnly="True"
                     <HeaderStyle Width="120px"></HeaderStyle> 
                    </telerik:GridBoundColumn> 
                    
                     <telerik:GridTemplateColumn  
                        UniqueName="DestFieldName"  
                        HeaderText="Destination Field" 
                        SortExpression="DestFieldName" 
                        Visible="true"
                        <FooterStyle VerticalAlign="Middle" HorizontalAlign="Center" /> 
                        <HeaderStyle Width="230px"></HeaderStyle> 
                        <ItemTemplate> 
                            <%#DataBinder.Eval(Container.DataItem, "DestFieldName")%> 
                        </ItemTemplate> 
                        <EditItemTemplate> 
                            <telerik:RadComboBox  
                              DataTextField="DestFieldName" 
                              DataValueField="DestFieldName" 
                              EnableLoadOnDemand="True" 
                              ID="RadComboBox1" 
                              runat="server" 
                              Height="140px" 
                              Width="220px" 
                                
                              DataSourceID="DestinationFields"
                            </telerik:RadComboBox> 
                        </EditItemTemplate> 
                    </telerik:GridTemplateColumn> 
                     
                    <telerik:GridEditCommandColumn FooterText="EditCommand footer" UniqueName="EditCommandColumn" 
                        HeaderText="Edit" HeaderStyle-Width="100px"
                    </telerik:GridEditCommandColumn> 
                     
              </Columns> 
           </MasterTableView> 
           <PagerStyle Mode="NumericPages"></PagerStyle> 
        </telerik:radgrid> 
         
         
        <asp:SqlDataSource ID="DestinationFields" runat="server" ConnectionString="<%$ ConnectionStrings:iBase_DM %>" 
            ProviderName="System.Data.SqlClient"  
             SelectCommand="SELECT FieldName as DestFieldName FROM DMProfileFieldMap WITH(NOLOCK)" > 
        </asp:SqlDataSource> 

Code Behind.

    Protected Sub RadGridFieldMappings_NeedDataSource(ByVal [source] As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGridFieldMappings.NeedDataSource 
        GetUserDetails() 
        Try 
            Me.RadGridFieldMappings.ClientSettings.Scrolling.AllowScroll = True 
            Me.RadGridFieldMappings.ClientSettings.Scrolling.UseStaticHeaders = True 
            Me.RadGridFieldMappings.ShowHeader = True 
            Me.RadGridFieldMappings.ShowFooter = True 
            Me.RadGridFieldMappings.ClientSettings.Resizing.AllowColumnResize = True 
            Me.RadGridFieldMappings.ClientSettings.Resizing.AllowRowResize = False 
            Me.RadGridFieldMappings.ClientSettings.Resizing.EnableRealTimeResize = True 
            Me.RadGridFieldMappings.ClientSettings.Resizing.ResizeGridOnColumnResize = True 
            Me.RadGridFieldMappings.ClientSettings.Resizing.ClipCellContentOnResize = True 
            Me.RadGridFieldMappings.ClientSettings.AllowColumnsReorder = True 
            Me.RadGridFieldMappings.ClientSettings.ReorderColumnsOnClient = True 
 
            strSQL = "SELECT" & vbCrLf 
            strSQL += " l.ListName," & vbCrLf 
            strSQL += " l.ListID," & vbCrLf 
            strSQL += " lf.ID, " & vbCrLf 
            strSQL += " lf.EmailAddrField, " & vbCrLf 
            strSQL += " lf.FieldName, mdfm.DestFieldName" & vbCrLf 
            strSQL += "FROM " & vbCrLf 
            strSQL += " AppControl.Messages m WITH(NOLOCK) INNER JOIN " & vbCrLf 
            strSQL += " AppControl.MessageLists ml WITH(NOLOCK)" & vbCrLf 
            strSQL += "     ON m.TaskID = ml.TaskID INNER JOIN " & vbCrLf 
            strSQL += " AppControl.Lists l WITH(NOLOCK)" & vbCrLf 
            strSQL += "     ON ml.ListID = l.ListID INNER JOIN " & vbCrLf 
            strSQL += " AppControl.ListFields lf WITH(NOLOCK)" & vbCrLf 
            strSQL += "     ON l.ListID = lf.ListID LEFT JOIN" & vbCrLf 
            strSQL += " AppControl.MessageDeployFieldMappings mdfm WITH(NOLOCK)" & vbCrLf 
            strSQL += "     ON m.TaskId = mdfm.TaskID " & vbCrLf 
            strSQL += "     AND lf.ID = mdfm.ListFieldID " & vbCrLf 
            strSQL += "WHERE" & vbCrLf 
            strSQL += " m.TaskID = " & TaskID & " " & vbCrLf 
            strSQL += " AND ml.IncludeList = 1" & vbCrLf 
            strSQL += " AND LoadIntoDMList = 1" & vbCrLf 
            strSQL += " AND EmailAddrField <> 1" & vbCrLf 
            If iTargetLists = 1 Then 
                RadGridFieldMappings.DataSource = ReadRecordsTargetLists(strSQL) 
                iTargetLists += 1 
            Else 
                Exit Sub 
            End If 
        Catch ex As Exception 
            Response.Redirect("ErrorPage.aspx?ErrorPage=" & Server.UrlEncode(ThisPage) & "&Exception=" & Server.UrlEncode(ex.Message)) 
        End Try 
    End Sub 
 
    Protected Sub RadGridFieldMappings_UpdateCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) 
        '?????????????????????????? 
    End Sub 

Im stumped on the following part. 
    Protected Sub RadGridFieldMappings_UpdateCommand(ByVal source As ObjectByVal e As GridCommandEventArgs) 
        '?????????????????????????? 
    End Sub 

Any help would be much appreciated.

thanks

3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 05 Oct 2009, 02:39 PM
Hi DavidA,

Try the following:

Dim item as GridItem = e.Item 
Dim combo as RadComnboBox = TryCast(item.FindControl("RadComboBox1"), RadComboBox) 
Dim value = combo.SelectedValue 


Best wishes,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
DavidA
Top achievements
Rank 1
answered on 05 Oct 2009, 10:21 PM
that did it - thanks.

Could you also post an example of how to get the value of  field in the same row. Its this field:

                  <telerik:GridBoundColumn UniqueName="ListID" HeaderText="ListID" DataField="ListID" Visible="True" ReadOnly="True">
                     <HeaderStyle Width="40px"></HeaderStyle>
                    </telerik:GridBoundColumn>

have a tried these examples with no luck: http://www.telerik.com/help/aspnet-ajax/grdaccessingcellsandrows.html

thanks



0
Princy
Top achievements
Rank 2
answered on 06 Oct 2009, 05:20 AM
Hello DavidA,

You can try out the following code to access the value of readonly cell in EditMode:
vb:
Protected Sub RadGridFieldMappings_UpdateCommand(ByVal source As ObjectByVal e As GridCommandEventArgs)  
      Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem) 
      Dim strtxt As String = item("ListID").Text  
 
End Sub  

Thanks
Princy.
Tags
Grid
Asked by
DavidA
Top achievements
Rank 1
Answers by
Veli
Telerik team
DavidA
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or