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

[Solved] Grid editing/insert

4 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gmoinaz
Top achievements
Rank 1
gmoinaz asked on 15 Jun 2009, 09:20 PM
I have a grid and I am trying to populate a dropdownlist when a user clicks on the edit or insert. Can this be done if I am using EditMode="InPlace"?  Thans for your help.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Jun 2009, 05:13 AM
Hi,

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.
0
gmoinaz
Top achievements
Rank 1
answered on 16 Jun 2009, 06:23 PM
Thanks for the response.  I guess the issue I'm having with alot of the examples is that I am not using a sqldatasource.  I am calling a custom database control(dll) that I use and so I tried this (vb):

 

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

 

0
gmoinaz
Top achievements
Rank 1
answered on 16 Jun 2009, 09:46 PM
Here is another example.  What am I doing wrong that the drop down list does not display after clicking on the edit button.  Instead a text box displays.

<

 

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>

 

0
Accepted
Yavor
Telerik team
answered on 22 Jun 2009, 05:50 AM
Hello gmoinaz,

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.
Tags
Grid
Asked by
gmoinaz
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
gmoinaz
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or