I want to display RadCombobox in the RadGrid when insert/edit operations perform. I want to display list of values that binds from one of the column of another table.
Also whatever i am binding data from another table, it should save in Radgrid record which i am displaying.
Thanks.
Best Regards
Arshad
4 Answers, 1 is accepted
You can use a RadComboBox in the EditItemTemplate of a TemplateColumn such that it displays in Edit/Insert mode of the grid. Also you can access the RadComboBox and set its DataSource to the required datatable.
aspx:
<telerik:GridTemplateColumn UniqueName="TemplateColumn1"> |
<EditItemTemplate> |
<telerik:RadComboBox ID="RadComboBox1" runat="server"> |
</telerik:RadComboBox> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
c#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridEditableItem && e.Item.IsInEditMode) |
{ |
GridEditableItem edited = (GridEditableItem)e.Item; |
RadComboBox combo = (RadComboBox)edited["TemplateColumn1"].FindControl("RadComboBox1"); |
combo.DataSource = ""; // Assign the data table here |
} |
} |
If you want to display a datafield of another table in your grid, then you can use the Join clause which helps combine records from two tables in a database.
Thanks
Princy.
I configure in edittemplate but its not displaying combobox. Something goes wrong with my code.
<
body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True"
DataSourceID="SqlDataSource1" GridLines="None">
<MasterTableView AutoGenerateColumns="False" CellSpacing="-1" CommandItemDisplay="Top"
DataKeyNames="Section_ID" DataSourceID="SqlDataSource1">
<EditItemTemplate>
<telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="Division_Name" DataValueField="Division_ID">
</telerik:RadComboBox>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ResourceUtilizationDBConnectionString %>"
SelectCommand="SELECT [Division_ID], [Division_Name] FROM [NSS_Divisions]"></asp:SqlDataSource>
</EditItemTemplate>
<Columns>
<telerik:GridBoundColumn DataField="Section_ID" DataType="System.Int32" HeaderText="Section_ID"
ReadOnly="True" SortExpression="Section_ID" UniqueName="Section_ID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Section_Name" HeaderText="Section_Name" SortExpression="Section_Name"
UniqueName="Section_Name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Divsion_ID" DataType="System.Int32" HeaderText="Divsion_ID"
SortExpression="Divsion_ID" UniqueName="Divsion_ID">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ResourceUtilizationDBConnectionString %>"
SelectCommand="SELECT * FROM [Division_Sections]"></asp:SqlDataSource>
</div>
</form>
</
body>
You have added EditItemTemplate to MasterTableView which is why the RadComboBox does not appear on the Grid , instead add a GridTemplateColumn to the column collection of the MasterTableView and then you can add RadComboBox to the EditItemTemplate of the GridTemplateColumn as shown below.
ASPX:
<Columns> |
<telerik:GridTemplateColumn HeaderText="HeaderText" UniqueName="TemplateColumn"> |
<EditItemTemplate> |
<telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="Division_Name" DataValueField="Division_ID"> |
</telerik:RadComboBox> |
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ResourceUtilizationDBConnectionString %>" |
SelectCommand="SELECT [Division_ID], [Division_Name] FROM [NSS_Divisions]"> |
</asp:SqlDataSource> |
</EditItemTemplate> |
<ItemTemplate> |
. . . |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
. . . |
</Columns> |
Checkout the GridTemplateColumn section of following link for more details.
Column types
Thanks,
Shinu.
I am new to ASP.Net as well as RAD controls. I have some problem while updating a record using automatic operations.
The scenario is as follows -
I have a grid which displays some information about the employees. I am using automatic operations to edit and delete a particular record. I have a column called as country which stores country_id from another table called "Country" which has 2 columns country_id and country_name. I want to display the country of an employee in the RAD grid column and when clicked on edit link button i want to display a combo box which shows a list of countries (This will be from table "Country" ). When user selects some another country it should get updated into the Employees table. (It should take country_id of selected item of combo and update into the Employees table.)
I am able to show the controls but I am getting the error on ItemUpdated. It says thats "Can not insert Null for column "country" Update Fails. " This means that the control is getting NULL value all the time. I have tried with different column types as well. I have also tried to attach a datasource on ItemDataBound event instead of giveing DataSourceID directly.
Please can anybody suggest a solution to this problem?