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

Can not find the DropDownlist in ItemDataBound

3 Answers 114 Views
Grid
This is a migrated thread and some comments may be shown as answers.
khalil_ck2002
Top achievements
Rank 1
khalil_ck2002 asked on 10 Mar 2011, 10:20 AM
Dears,

I downloaded the Telerik Ajax Controls and I'm trying to apply the  Grid View as the following :

<telerik:RadGrid ID="RadGrid1" runat="server" CssClass="RadGrid" GridLines="None"
AllowPaging="True" PageSize="20" AllowSorting="True" AutoGenerateColumns="False"
ShowStatusBar="True" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted"
OnItemUpdated="RadGrid1_ItemUpdated" OnItemCommand="RadGrid1_ItemCommand" OnPreRender="RadGrid1_PreRender">
<MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="الأجراء">
<CommandItemSettings ExportToPdfText="Export to Pdf" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn CancelText="الغاء" EditText="تعديل" InsertText="حفظ"
UpdateText="تعديل">
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn UniqueName="Case Id" HeaderText="رقم الحالة" DataField="الحالة">
<HeaderStyle ForeColor="Silver" Width="20px"></HeaderStyle>
<ItemStyle ForeColor="Gray" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Activity UID" HeaderText="رقم الأجراء" DataField="الأجراء">
<HeaderStyle ForeColor="Silver" Width="20px"></HeaderStyle>
<ItemStyle ForeColor="Gray" />
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Type" HeaderText="نوع الأجراء" DataField="نوع">
<HeaderStyle Width="60px"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Created" HeaderText="تاريخ الأجراء" DataField="تاريخ"
DataFormatString="{0:d}">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Owned By" HeaderText="الموظفين" DataField="الموظفين">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Description" HeaderText="الوصف" DataField="الوصف">
</telerik:GridBoundColumn>
<telerik:GridButtonColumn CommandName="Delete" Text="حذف" UniqueName="column">
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<EditColumn FilterControlAltText="Filter EditCommandColumn1 column" UniqueName="EditCommandColumn1">
</EditColumn>
<FormTemplate>
<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
style="border-collapse: collapse; background: white;">
<tr class="EditFormHeader">
<td colspan="2" style="font-size: small">
<b></b>
</td>
</tr>
<tr>
<td colspan="2">
<b></b>
</td>
</tr>
<tr>
<td>
<table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
رقم الأجراء:
</td>
<td>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("الأجراء") %>'>
</asp:TextBox>
</td>
</tr>
<tr>
<td>
الموظفين:
</td>
<td>
<asp:TextBox ID="TextBox8" runat="server" Text='<%# Bind("الموظفين") %>' TabIndex="1">
</asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td>
تاريخ الأجراء:
</td>
<td>
<telerik:RadDatePicker ID="BirthDatePicker" runat="server" MinDate="1/1/1900" DbSelectedDate='<%# Eval("تاريخ") %>'
TabIndex="4">
</telerik:RadDatePicker>
</td>
</tr>
<tr>
<td>
نوع الأجراء
</td>
<td>
<asp:DropDownList ID="ddlTOC" runat="server" TabIndex="7" AppendDataBoundItems="True">
<asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</td>
<td>
<table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0" class="module">
<tr>
<td>
الوصف:
</td>
</tr>
<tr>
<td>
<asp:TextBox ID="TextBox1" Text='<%# Bind("الوصف") %>' runat="server" TextMode="MultiLine"
Rows="5" Columns="40" TabIndex="5">
</asp:TextBox>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate" Text='<%#"تعيل" %>' runat="server" CommandName='<%# "Update" %>'>
</asp:Button>&nbsp;
<asp:Button ID="btnCancel" Text="الغاء" runat="server" CausesValidation="False" CommandName="Cancel">
</asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowDblClick="RowDblClick" />
</ClientSettings>
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
</HeaderContextMenu>
</telerik:RadGrid>

And I'm trying to get the Asp dropdownlist from it in ItemDataBound By this Code :
Dim dropDownList As DropDownList = DirectCast(RadGrid1.FindControl("ddlTOC"), DropDownList)

But this Return Nothing

Any Herp I will be grateful
Thank you

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Mar 2011, 10:30 AM
Hello Khalil,

Since the DropDownList is inside FormTemplate, you need to check whether the grid is in edit mode and get the GridEditFormItem first. Then using FindControlmethod access the DropDownList like below.

Vb.Net:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
        Dim editItem As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
        Dim dropDownList As DropDownList = DirectCast(editItem.FindControl("ddlTOC"), DropDownList)
    End If
End Sub

Thanks,
Princy.
0
khalil_ck2002
Top achievements
Rank 1
answered on 10 Mar 2011, 10:39 AM

Dear Princy,

 

Thank You for your response ,but I'm alrady put this  code and its not working

 

0
khalil_ck2002
Top achievements
Rank 1
answered on 10 Mar 2011, 11:10 AM
Hello Princy,
its wokring now
thank you I will make it as an answer
Tags
Grid
Asked by
khalil_ck2002
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
khalil_ck2002
Top achievements
Rank 1
Share this question
or