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

Radgrid Columns in Edit Mode

3 Answers 402 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Deepak
Top achievements
Rank 1
Deepak asked on 18 Jul 2011, 04:21 PM
Hi, I am new to this forum and new to rad controls. I have spent a little time on understanding the usage of these control and no trying to implement one.

I have a radgrid binded to a datatable(code behind). I would like to display dropdown for a column(say Prefix) with prefilled values from another datatable when in Edit Mode. I tried using GridDropDownColumn this does not display data for that column but does gives me a dropdown control in Edit mode.

I have the grid this way.
-----------------------------Control---------------------------------------------
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" OnNeedDataSource="RadGrid1_NeedDataSource"
                AllowSorting="true" GridLines="None" PageSize="5" Skin="Web20"
        Width="80%" onpageindexchanged="RadGrid1_PageIndexChanged"
        onpagesizechanged="RadGrid1_PageSizeChanged"
        OnUpdateCommand="RadGrid1_UpdateCommand"
        onitemdatabound="RadGrid1_ItemDataBound">
                <ClientSettings AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
                    <Selecting AllowRowSelect="true" />
                    <Resizing AllowColumnResize="True" AllowRowResize="false" ResizeGridOnColumnResize="false"
                    ClipCellContentOnResize="true" EnableRealTimeResize="false" AllowResizeToFit="true" />
                </ClientSettings>
                <MasterTableView Width="100%" AutoGenerateColumns="false" >
                    <Columns>
                        <telerik:GridButtonColumn CommandName="Edit" Text="Edit" UniqueName="Edit">
                        </telerik:GridButtonColumn>
                        <telerik:GridButtonColumn CommandName="Replace" Text="Replace" UniqueName="Replace">
                        </telerik:GridButtonColumn>
                        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="Delete">
                        </telerik:GridButtonColumn>
                        <telerik:GridBoundColumn DataField="P" HeaderText="Prefix">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="FN" HeaderText="FirstName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="MN" HeaderText="MiddleI">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="LN" HeaderText="LastName">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="SchoolName" HeaderText="LocatedAt">
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="PersonID" HeaderText="PersonID" Visible="false" UniqueName="PersonID">
                        </telerik:GridBoundColumn>
                    </Columns>
                </MasterTableView>
                <PagerStyle Mode="NextPrevAndNumeric" />

            </telerik:RadGrid>
-----------------------------CodeBehind---------------------------------------------
Page Load :-
RadGrid1.DataSource = dsAdminInfo.Tables[0];<br>
RadGrid1.DataBind();


 protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            RadGrid1.DataSource = ((DataSet)Session["AdminInfo"]).Tables[0];
        }

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
            {
                GridEditFormItem editform = (GridEditFormItem)e.Item;
                editform["PersonID"].Parent.Visible = false;
        }

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Jul 2011, 05:42 AM
Hello Deepak,

In normal mode, the DropdownColumn looks like normal Bound column and in Editmode it renders as DropDown. In your case you can use Template column with Dropdown in item template.
aspx:
<telerik:GridTemplateColumn>
     <ItemTemplate>
       <asp:DropDownList  DataTextField="LastName" DataValueField="LastName" runat="server" DataSourceID="SqlDataSource1">
      </asp:DropDownList>
     </ItemTemplate>
</telerik:GridTemplateColumn>
Also check out the following documentation for more on column types.
Column Types.

Thanks,
Shinu.
0
Deepak
Top achievements
Rank 1
answered on 19 Jul 2011, 02:06 PM
Thanks for the reply. BUt this is where I am confused. I am not using SQLDataSource. I have a datatable. How do you do it with a datatable or dataset?

0
Marin
Telerik team
answered on 22 Jul 2011, 03:27 PM
Hi Deepak,

 If you use the GridDropDownColumn you should bound its RadComboBox control in the ItemDataBound event. You can have a look at this help topic providing more information on the question. Also another option might be if you use standard ASP.NET DropDown in a EditItemTemaplate of the GridTemplateColumn. This approach is shown here.

Kind regards,
Marin
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Deepak
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Deepak
Top achievements
Rank 1
Marin
Telerik team
Share this question
or