binding dataset to grid template column

Posted by Arun11 under ASP.NET on 7/7/2011 | Points: 10 | Views : 4340 | Status : [Member] | Replies : 5
Hi,

can anyone tell me how to bind dataset to a grid template column?please give me the code.

Thanks




Responses

Posted by: Ndebata on: 7/7/2011 [Member] Starter | Points: 25

Up
0
Down
Lets say your dataset is having a table with Column name "MyName "
In the Template Column you can add an ASP.Net server control
Here I am just adding a Label
<asp:TemplateField HeaderText="My Name" >

<HeaderStyle HorizontalAlign="Left" Width="180px" />
<ItemTemplate>
<asp:Label ID="lblName" runat="server" Visible="false" Text='<%# Bind("MyName") %>'></asp:Label>
</ItemTemplate>
<ItemStyle Width="170px" HorizontalAlign="Left" />
</asp:TemplateField>

http://msdn.microsoft.com/en-us/library/ms228046.aspx
http://blog.developers.ie/cgreen/archive/2006/05/22/2036.aspx

Arun11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 7/7/2011 [Member] Starter | Points: 25

Up
0
Down
first desing dridview by changing property autogeneratecolumns=false
then
<templatefiled>

<itemtemplate><asl:lable id="lable1" runat="server" text='<#Eval("colname")>'></asp:label></itemtemplate>
.........
</templatefield>

give as many as columns you want

and in code benind

sqldataadapter da=new sqldataadapter("select * from tablename",cn);

dataset ds=new dataset();

da.fill(ds);
gridview1.datasource=ds;
gridview1.databind();


Thanks&Regards
LakshmiNarayana Nalluri.

Arun11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arun11 on: 7/7/2011 [Member] Starter | Points: 25

Up
0
Down
But i dont want to use query in code behind..Because i am getting the data in the DAL using dataset.In this case what do i need to write in code behind?I tried below but its not working:

aspx:

<telerik:GridTemplateColumn HeaderText="Template Name">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem,("TemplateName") %>
</ItemTemplate>
</telerik:GridTemplateColumn>
aspx.cs:

DataSet ds = new SHTemplateUI().GetSHTemplateListByUserUI();//calling UI function
this.rgTemplateList.DataSource = ds;
this.rgTemplateList.DataBind();



Arun11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 7/7/2011 [Member] Starter | Points: 25

Up
0
Down
First try to remove extra parenthesis ( from
<%#DataBinder.Eval(Container.DataItem,"TemplateName") %> 

Then check do you have a column named
TemplateName
, if not provide the appropriate name

Arun11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arun11 on: 7/7/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Ndebata,

i checked both...its fine..but still data is not populating..i think i need to add something in code behind.

Arun11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response