Hi,
In the below code am using dropdowns and listbox controls. I need to bind the value from DB for these controls in code behind.
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server" ShowStatusBar="true"
AutoGenerateColumns="False" PageSize="3" AllowSorting="True" AllowMultiRowSelection="False"
AllowPaging="false" AllowAutomaticDeletes="false" AllowAutomaticInserts="false"
AllowAutomaticUpdates="false"
OnDetailTableDataBind="RadGrid1_DetailTableDataBind" OnNeedDataSource="RadGrid1_NeedDataSource" >
<MasterTableView DataKeyNames="EmpID" AllowMultiColumnSorting="True"
Width="100%" CommandItemDisplay="Top" Name="Students">
<DetailTables>
<telerik:GridTableView DataKeyNames="Semester,Grade" Width="100%" runat="server" CommandItemDisplay="Top" Name="Details">
<ParentTableRelation>
<telerik:GridRelationFields DetailKeyField="EmpID" MasterKeyField="EmpID"></telerik:GridRelationFields>
</ParentTableRelation>
<Columns>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn1">
<HeaderStyle Width="20px"></HeaderStyle>
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn HeaderText="semester" DataField="Semester"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Grade" DataField="Grade"></telerik:GridBoundColumn>
<telerik:GridButtonColumn UniqueName="DeleteColumn1" Text="Delete" CommandName="Delete"> </telerik:GridButtonColumn>
</Columns>
<EditFormSettings EditFormType="Template" >
<FormTemplate>
<table cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;">
<tr>
<td style="padding-left: 5px; width: 50%;" align="left">
<asp:Label ID="Label3" runat="server" CssClass="DisplayLabel" Text="Semester"></asp:Label> <br />
<asp:DropDownList ID="ddlSemester" runat="server">
<asp:ListItem Selected="True"> -- Select -- </asp:ListItem>
</asp:DropDownList>
</td>
<td style="padding-left: 5px; width: 50%;" align="left">
<asp:Label ID="Label1" runat="server" CssClass="DisplayLabel" Text="Grade"></asp:Label> <br />
<asp:DropDownList ID="ddlGrade" runat="server">
<asp:ListItem Selected="True"> -- Select -- </asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' CssClass="button"></asp:Button>
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel" CssClass="button"></asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
<NoRecordsTemplate>
<div>
There are no records to display
</div>
</NoRecordsTemplate>
</telerik:GridTableView>
</DetailTables>
<Columns>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn1">
<HeaderStyle Width="20px"></HeaderStyle>
</telerik:GridEditCommandColumn>
<telerik:GridBoundColumn HeaderText="Student ID" DataField="EmpID"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Student Name" DataField="EmpName"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Degree" DataField="Degree"></telerik:GridBoundColumn>
<telerik:GridBoundColumn HeaderText="Department" DataField="Dept"></telerik:GridBoundColumn>
<telerik:GridButtonColumn UniqueName="DeleteColumn2" Text="Delete" CommandName="Delete"> </telerik:GridButtonColumn>
</Columns>
<NoRecordsTemplate>
<div>
There are no records to display
</div>
</NoRecordsTemplate>
<EditFormSettings EditFormType="Template" >
<FormTemplate>
<table cellspacing="2" cellpadding="1" width="100%" border="0" rules="none" style="border-collapse: collapse;">
<tr>
<td style="padding-left: 5px; width: 30%;" align="left">
<asp:Label ID="Label3" runat="server" CssClass="DisplayLabel" Text="Student ID"></asp:Label>
<br />
<asp:TextBox ID="TextBox1" runat="server" Width="90%" Text='<%# Bind("EmpID") %>'></asp:TextBox>
</td>
<td style="padding-left: 5px; width: 30%;" align="left">
<asp:Label ID="Label6" runat="server" CssClass="DisplayLabel" Text="Student Name"></asp:Label>
<br />
<asp:TextBox ID="TextBox2" runat="server" Width="90%" Text='<%# Bind("EmpName") %>'></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td style="padding-left: 5px; width: 30%;" align="left">
<asp:Label ID="Label7" runat="server" CssClass="DisplayLabel" Text="Degree"></asp:Label>
<br />
<asp:ListBox ID="ListBox1" runat="server" Width="50%" AppendDataBoundItems="true" SelectionMode="Multiple">
<asp:ListItem Selected="True"> -- Select -- </asp:ListItem>
</asp:ListBox>
</td>
<td style="padding-left: 5px; width: 30%;" align="left">
<asp:Label ID="Label8" runat="server" CssClass="DisplayLabel" Text="Department"></asp:Label>
<br />
<asp:ListBox ID="ListBox2" runat="server" Width="50%" AppendDataBoundItems="true" SelectionMode="Multiple">
<asp:ListItem Selected="True"> -- Select -- </asp:ListItem>
</asp:ListBox>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td align="right" colspan="2">
<asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' CssClass="button"></asp:Button>
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" CommandName="Cancel" CssClass="button"></asp:Button>
</td>
</tr>
</table>
</FormTemplate>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
In code behind
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
{
GridEditableItem item = e.Item as GridEditableItem;
if (e.Item.OwnerTableView.Name == "Students")
{
GridEditFormItem editFormItem = (GridEditFormItem)e.Item;
ListBox listBox1= editFormItem.FindControl("ListBox1") as ListBox;
}
}
}
Am getting null value when find the listbox.
Kindly help me to sort out this issue.
Regards,
Ganeshkumar