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

Referencing a GridDropDownColumn from server-side on postback

4 Answers 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Shane Clay
Top achievements
Rank 1
Shane Clay asked on 26 Apr 2011, 02:20 PM
Hi All

I have a RadGrid as follows:

<telerik:RadGrid ID="trgStudAttend" runat="server" AllowSorting="True" 
    AutoGenerateColumns="False" GridLines="None" Skin="Windows7" 
    CellSpacing="0" AllowMultiRowEdit="True">
    <ClientSettings EnableRowHoverStyle="true" />
    <MasterTableView DataKeyNames="atdID" EditMode="InPlace">
        <Columns>
            <telerik:GridBoundColumn DataField="atdID" HeaderText="ID" Visible="false" 
                UniqueName="atdID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="studDisplayName" HeaderText="Name"
                UniqueName="studDisplayName" ReadOnly="True">
            </telerik:GridBoundColumn>
            <telerik:GridDropDownColumn DataSourceID="sdsTimeOfDayCodes" HeaderText="Time of Day" 
                ListTextField="comb" ListValueField="todcCode" UniqueName="todcCode" DataField="atdTimeOfDayCode">
            </telerik:GridDropDownColumn>
            <telerik:GridDropDownColumn DataSourceID="sdsReasonCodes" HeaderText="Reason" 
                ListTextField="comb" ListValueField="rfacCode" UniqueName="rfacCode" DataField="atdReasonCode">
            </telerik:GridDropDownColumn>
            <telerik:GridBoundColumn DataField="atdComment" HeaderText="Comment"
                UniqueName="atdComment">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

At post back, every item is in edit mode.

I also have a button on my page (trbSave). When clicked, I want to loop through each row in my RadGrid, and determine what the selected value is for my drop down columns. I am trying this so far without any luck:

' Declarations
Dim sqlString As String = ""
Dim sqlCom As SqlCommand
Dim todcDDL As RadComboBox
' Loop through each student in the radgrid, and save the selected values to the details database
For Each i As GridDataItem In trgStudAttend.EditItems
    todcDDL = i.FindControl("todcCode")
Next

i.FindControl("todcCode") always returns 'nothing'. Does anyone know how I can reference that drop downlist and get its currently selected value?

Shane

4 Answers, 1 is accepted

Sort by
0
Shane Clay
Top achievements
Rank 1
answered on 26 Apr 2011, 02:45 PM
I was able to get a reference to my control by doing the following:

todcDDL = i("todcCode").Controls(0)

The i("todcCode") gets the actual TableCell, then .Controsl(0) gets the first control in that cell which is the drop down box.

Is this the most simple way of doing this? Seems more complex than it should be.
0
Elliott
Top achievements
Rank 2
answered on 26 Apr 2011, 10:00 PM
Protected Sub gvVendor_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvVendor.ItemCommand
    Dim gdItem As GridDataItem = Nothing
    Dim gefItem As GridEditFormItem = Nothing
    Select Case e.CommandName
        Case "PerformInsert"
            gdItem = DirectCast(e.Item, GridDataItem)
            InsertVendor(gdItem)
        Case "Edit"
            gdItem = DirectCast(e.Item, GridDataItem)
        Case "Update"
            gdItem = DirectCast(e.Item, GridDataItem)
            UpdateVendor(gdItem)
        Case "Delete"
    End Select
End Sub
 
 
Private Sub InsertVendor(ByVal gdItem As GridDataItem)
    Dim VendorID As Integer = 0
    Dim txtLNSPrefix, txtKMSPrefix, txtVendorName As TextBox
    ' Dim txtRepGroup as TextBox
    Dim chkRepGroup, chkRegistration As CheckBox
    Dim rcbRepGroup As RadComboBox = Nothing
    Dim rcbItem As RadComboBoxItem = Nothing
    Dim intRepGroupID As Integer = 0
    Dim strRepGroup As String = String.Empty
    Dim ws As CommonFunctions
 
    txtLNSPrefix = DirectCast(gdItem("LNSPrefix").Controls(0), TextBox)
    txtKMSPrefix = DirectCast(gdItem("KMSPrefix").Controls(0), TextBox)
    txtVendorName = DirectCast(gdItem("VendorName").Controls(0), TextBox)
    chkRepGroup = DirectCast(gdItem("RepGroupFlag").Controls(0), CheckBox)
    rcbRepGroup = DirectCast(gdItem("RepGroup").Controls(0), RadComboBox)
    rcbItem = DirectCast(rcbRepGroup.SelectedItem, RadComboBoxItem)
    intRepGroupID = rcbRepGroup.SelectedValue
    If intRepGroupID > 0 Then
        strRepGroup = rcbItem.Text
    End If
    chkRegistration = DirectCast(gdItem("RegistrationFlag").Controls(0), CheckBox)
    ws = New CommonFunctions
    VendorID = ws.InsertVendor(txtLNSPrefix.Text, txtKMSPrefix.Text, _
        txtVendorName.Text, chkRepGroup.Checked, strRepGroup, _
        intRepGroupID, chkRegistration.Checked)
    ws = Nothing
End Sub
 
Private Sub UpdateVendor(ByVal gdItem As GridDataItem)
    Dim VendorID As Integer = 0
    Dim txtLNSPrefix, txtKMSPrefix, txtVendorName As TextBox
    ' Dim txtRepGroup as TextBox
    Dim chkRepGroup, chkRegistration As CheckBox
    Dim rcbRepGroup As RadComboBox = Nothing
    Dim rcbItem As RadComboBoxItem = Nothing
    Dim intRepGroupID As Integer = 0
    Dim strRepGroup As String = String.Empty
    Dim ws As CommonFunctions
 
    VendorID = CInt(gdItem.OwnerTableView.DataKeyValues(gdItem.ItemIndex)("VendorID"))
    txtLNSPrefix = DirectCast(gdItem("LNSPrefix").Controls(0), TextBox)
    txtKMSPrefix = DirectCast(gdItem("KMSPrefix").Controls(0), TextBox)
    txtVendorName = DirectCast(gdItem("VendorName").Controls(0), TextBox)
    chkRepGroup = DirectCast(gdItem("RepGroupFlag").Controls(0), CheckBox)
    rcbRepGroup = DirectCast(gdItem("RepGroup").Controls(0), RadComboBox)
    rcbItem = DirectCast(rcbRepGroup.SelectedItem, RadComboBoxItem)
    intRepGroupID = rcbRepGroup.SelectedValue
    If intRepGroupID > 0 Then
        strRepGroup = rcbItem.Text
    End If
    '  txtRepGroup = DirectCast(gdItem("RepGroup").Controls(0), TextBox)
    chkRegistration = DirectCast(gdItem("RegistrationFlag").Controls(0), CheckBox)
    ws = New CommonFunctions
    ws.UpdateVendor(VendorID, txtLNSPrefix.Text, txtKMSPrefix.Text, _
        txtVendorName.Text, chkRepGroup.Checked, strRepGroup, _
        intRepGroupID, chkRegistration.Checked)
    ws = Nothing
End Sub

yes but can you use a RADComboBox instead of a dropdownlist?
0
Iana Tsolova
Telerik team
answered on 29 Apr 2011, 09:51 AM
Hi Marianne,

Try accessing the RadComboBox of the GridDropDownColumn through the column editor:
Dim editManager editManager as GridEditManager = gdItem.EditManager;
Dim dropDownListColumnEitor as GridDropDownListColumnEditor = 
    CType(editManager.GetColumnEditor("GridDropDownColumn_UniqueID"), GridDropwDownListColumnEditor)
Dim combo as RadComboBox = dropDownListColumnEitor.ComboBox

Let me know if this works.

Regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Elliott
Top achievements
Rank 2
answered on 29 Apr 2011, 02:29 PM
Iana-I was only suggesting to Shane that using a RADComboBox instead of a Microsoft DropDownList (or ComboBox) would clean up code
my solution was awkward but it's in production so I'd rather not do any refactoring at this point
Tags
Grid
Asked by
Shane Clay
Top achievements
Rank 1
Answers by
Shane Clay
Top achievements
Rank 1
Elliott
Top achievements
Rank 2
Iana Tsolova
Telerik team
Share this question
or