4 Answers, 1 is accepted
I suppose that you have placed the dropdownlist in the EditItemTemplate of a GridTemplateColumn. If thats the case, you can try out the following code to populate the dropdownlist on clicking the edit or insert buttons.
aspx:
| <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AutoGenerateColumns="true" runat="server" OnItemDataBound="RadGrid1_ItemDataBound"> |
| <MasterTableView CommandItemDisplay="Top" EditMode="InPlace"> |
| <Columns> |
| <telerik:GridEditCommandColumn></telerik:GridEditCommandColumn> |
| <telerik:GridButtonColumn Text="Increase" ButtonType="PushButton" UniqueName="btnProcess"> |
| </telerik:GridButtonColumn> |
| <telerik:GridTemplateColumn UniqueName="TemplateColumn"> |
| <ItemTemplate> |
| ...... |
| </ItemTemplate> |
| <EditItemTemplate> |
| <asp:DropDownList ID="DropDownList1" runat="server"> |
| </asp:DropDownList> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| ..... |
c#:
| protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
| { |
| GridEditableItem item = (GridEditableItem)e.Item; |
| DropDownList ddl = (DropDownList)item.FindControl("DropDownList1"); |
| ddl.DataSourceID = "SqlDataSource1"; |
| ddl.DataTextField = "CompanyName"; |
| } |
| } |
Thanks
Princy.
If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
Dim ddl As DropDownList = DirectCast(item.FindControl("ddlType"), DropDownList)
DB.ConnectDatabase()
colParams.Clear()
Dim ddlTable As DataTable = DB.GetData("MyQuery", Write, colParams)
ddl.DataSource = ddlTable '-----generates error here
ddl.DataTextField =
"TYPE"
ddl.DataBind()
DB.Close(ddlTable)
DB.CloseConnection()
DB =
Nothing
End If
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server">
<title></title>
</
head>
<
body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"
EnableTheming="True">
</telerik:RadScriptManager>
<div>
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Vista"
GridLines="None" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
Width="97%" OnNeedDataSource="RadGrid1_NeedDataSource"
OnDeleteCommand="RadGrid1_DeleteCommand"
OnInsertCommand="RadGrid1_InsertCommand"
OnUpdateCommand="RadGrid1_UpdateCommand" >
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
<MasterTableView DataKeyNames="RFSNO" GridLines="None" Width="100%" AllowFilteringByColumn="false" AllowSorting="true"
CommandItemDisplay ="TopAndBottom" EditMode="InPlace" >
<Columns>
<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="Delete">
</telerik:GridButtonColumn>
<telerik:GridBoundColumn DataField="NO" HeaderText="No" UniqueName="NO" ReadOnly="True"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TYPE" HeaderText="Type" UniqueName="TYPE"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="NAME" HeaderText="Name" UniqueName="NAME"></telerik:GridBoundColumn>
<telerik:GridEditCommandColumn>
</telerik:GridEditCommandColumn>
</Columns>
<EditItemTemplate>
<table id="Table2" cellspacing="2" cellpadding="1" width="100%" border="0" rules="none"
style="border-collapse: collapse; background: white;">
<tr>
<td colspan="2" style="font-size: small">
<b>RFS Details</b></td>
</tr>
<tr>
<td>
<table id="Table3" cellspacing="1" cellpadding="1" width="250" border="0">
<tr>
<td>
Folder Name:
</td>
<td>
<asp:TextBox ID="txtIniName" runat="server" Text='<%# Bind( "FOLDER") %>' TabIndex="1">
</asp:TextBox>
</td>
</tr>
<tr>
<td>Type:</td>
<td>
<asp:DropDownList ID="ddlType" runat="server" SelectedValue='<%# Bind("TYPE") %>' DataSource='<%# (New string() { "EXE", "DLL", "RPT" }) %>'
TabIndex="2" AppendDataBoundItems="true">
<asp:ListItem Selected="True" Text="Select" Value=""></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</table>
</td>
</tr>
</table>
</EditItemTemplate>
<ExpandCollapseColumn Visible="False">
<HeaderStyle Width="19px"></HeaderStyle>
</ExpandCollapseColumn>
<RowIndicatorColumn Visible="False">
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</
body>
</
html>
To make sure the dropdown is properly shown, you can either use a dropdowncolumn, or a form template. I hope one of these options is suitable for you.
Best wishes,
Yavor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.