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

Problem with Template Column in RadGrid

3 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vijay
Top achievements
Rank 2
Vijay asked on 01 Nov 2010, 02:56 PM
Hello,

i have radgrid which has two bound columns and two template columns with radcombobox in edititemtemplate ..i've given the items their itself with values ...values to them will be coming from database.....my problem is that they r showing values which r coming directly from database .with out showing their text.. .

EX:-in the rad grid display  it is showing lvl1 instead of LEVEL1

Here is my code

<

telerik:RadGrid ID="grdCMS" runat="server" OnNeedDataSource="grdCMS_NeedDataSource"

 

 

AutoGenerateColumns="False" OnInsertCommand="grdCMS_Insert" OnItemCreated="grdCMS_ItemCreated"

 

 

OnItemDataBound="grdCMS_ItemDataBound" OnEditCommand="Editing"

 

 

OnDeleteCommand="grdCMS_Delete" OnItemCommand="grdCMS_ItemCommand" AllowSorting="true">

 

 

<MasterTableView CommandItemDisplay="Top" EditMode="InPlace" DataKeyNames="seqNo">

 

 

<Columns>

 

 

<telerik:GridEditCommandColumn UpdateText="Update" ButtonType="ImageButton" ></telerik:GridEditCommandColumn>

 

 

<telerik:GridDropDownColumn DataField="seqNo" ListTextField="seqNo" ListValueField="seqNo" ListDataMember="testcms"

 

 

UniqueName="seqNo" HeaderText="Sequence Number">

 

 

 

</telerik:GridDropDownColumn>

 

 

<telerik:GridBoundColumn DataField="lvlqtn" HeaderText="Levelling Question" UniqueName="lvlqtn" >

 

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridTemplateColumn>

 

 

<HeaderTemplate>

 

 

<asp:Label ID="lblhdryes" Text="Level If Yes" runat="server"></asp:Label>

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

 

 

<asp:Label ID="lbllvlyes" runat="server" Text='<%# Eval("lvlyes") %>'></asp:Label>

 

 

</ItemTemplate>

 

 

<EditItemTemplate>

 

 

<telerik:RadComboBox ID="rcblvlyes" runat="server" >

 

 

<Items>

 

 

<telerik:RadComboBoxItem Text="Level1" Value="lvl1" />

 

 

<telerik:RadComboBoxItem Text="Level2" Value="lvl2" />

 

 

<telerik:RadComboBoxItem Text="Level3" Value="lvl3" />

 

 

<telerik:RadComboBoxItem Text="Level4" Value="lvl4" />

 

 

</Items>

 

 

</telerik:RadComboBox>

 

 

</EditItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

<telerik:GridTemplateColumn>

 

 

<HeaderTemplate>

 

 

<asp:Label ID="lblhdrlvlno" Text="Level If NO" runat="server"></asp:Label>

 

 

</HeaderTemplate>

 

 

<ItemTemplate>

 

 

<asp:Label ID="lbllvlno" runat="server" Text='<%# Eval("lvlno") %>'></asp:Label>

 

 

</ItemTemplate>

 

 

<EditItemTemplate>

 

 

<telerik:RadComboBox ID="rcblvlno" runat="server">

 

 

<Items>

 

 

<telerik:RadComboBoxItem Text="Level1" Value="lvl1" />

 

 

<telerik:RadComboBoxItem Text="Level2" Value="lvl2" />

 

 

<telerik:RadComboBoxItem Text="Level3" Value="lvl3" />

 

 

<telerik:RadComboBoxItem Text="Level4" Value="lvl4" />

 

 

</Items>

 

 

</telerik:RadComboBox>

 

 

</EditItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

 

<telerik:GridButtonColumn CommandName="Delete" Text="Delete"

 

 

ButtonType="ImageButton" ConfirmText="Do u Want to Delete the row" ConfirmTitle="Confirmation" ConfirmDialogType="RadWindow"></telerik:GridButtonColumn>

 

 

</Columns>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>


 

3 Answers, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 02 Nov 2010, 02:46 PM
Hi Vijay,

When you configure a GridDropDownColumn in order to show different values for the text filed of the combobox and for ithe value behind it, you need to use these two properties:
ListValueField - set it to be equal to the filed, retreived from the database
ListTextField - set it to the value that you would like to see shown as text in the combo box.

For more information on configuring the GridDropDownColumn please check the following help topic and live demo.

Best wishes,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vijay
Top achievements
Rank 2
answered on 03 Nov 2010, 06:55 AM
Hi Marin,

Thanks For u r Reply...

But in my scenario i dont have a Griddropdown column..i have a temple column  of below format 

<telerik:GridTemplateColumn HeaderText="Level If NO">
<HeaderTemplate>    
 <asp:Label ID="lblhdrlvlno" Text="Level If NO" runat="server"></asp:Label>    
 </HeaderTemplate>    
<ItemTemplate>    
 <asp:Label ID="lbllvlno" runat="server" Text='<%# Eval("lvlno") %>'></asp:Label>    
 </ItemTemplate> 
 <EditItemTemplate>
 <telerik:RadComboBox ID="rcblvlno" runat="server" AppendDataBoundItems="true">
 <Items>
<telerik:RadComboBoxItem  Text="Please Select.." Value="0"/>
 <telerik:RadComboBoxItem Text="Level1" Value="lvl1" />
 <telerik:RadComboBoxItem Text="Level2" Value="lvl2" />
 <telerik:RadComboBoxItem Text="Level3" Value="lvl3" />
 <telerik:RadComboBoxItem Text="Level4" Value="lvl4" />
 </Items>
  </telerik:RadComboBox>
 </EditItemTemplate>
  </telerik:GridTemplateColumn>



The Thing is values are coming from Database(lvl1,lvl2,lvl3...) and the text is in radcombobox items..how could i map those two things to display text in the radgrid...
0
Accepted
Marin
Telerik team
answered on 03 Nov 2010, 03:49 PM
Hello Vijay,

The declarative way you have bound the label in the item template of the template column will show only the value coming from the database. In order to bind it to another value you might try setting the desired value in code-behind in the ItemDataBound event like this:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridDataItem)
           {
               Label lbl = (e.Item as GridDataItem)["TemplateColumnUniqueName"].FindControl("lbllvlno") as Label;
               //set the disered text of the label here (possibly through a database query)
               // if lbl.text=="lbl1" set lbl.text="Level1"
           }
       }

To retrieve the concrete template column it must have a unique name property set in the markup.

Hope this helps, let me know if you have any other questions.

Greetings,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Vijay
Top achievements
Rank 2
Answers by
Marin
Telerik team
Vijay
Top achievements
Rank 2
Share this question
or