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

Problem binding data with custom attribute.

3 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zakir
Top achievements
Rank 1
Zakir asked on 15 Oct 2013, 08:48 AM

 

Hi,

I am not able to bind the data with custom data attribute.
Is it possible to bind the data in telerik grid control?
I am trying like this..


 

 

<Columns>

  <telerik:GridTemplateColumn Display="false"> 
    <ItemTemplate>
      <asp:Label runat="server" ID="lblRowStyle"  
        data-IsDevStrikeThrough='<%# Bind("IsDevStrikeThrough") %>'
        data-IsDevShowAsterik='<%# Bind("IsDevShowAsterik") %>'
        data-IsDevEditable='<%# Bind("IsDevEditable") %>'/>
    </ItemTemplate>  

  </telerik:GridTemplateColumn>

</Columns>

 

 

 

 

<Columns>

  <telerik:GridTemplateColumn Display="false">

    <ItemTemplate>

      <asp:Label runat="server" ID="lblRowStyle"  
       data-IsDevStrikeThrough='<%# DataBinder.Eval(Container, "Attributes['IsDevStrikeThrough']") %>'
       data-IsDevShowAsterik='<%# DataBinder.Eval(Container, "Attributes['IsDevShowAsterik']") %>'
       data-IsDevEditable='<%# DataBinder.Eval(Container, "Attributes['IsDevEditable']")/>
     </ItemTemplate>  

  </telerik:GridTemplateColumn>

</Columns>

 

Kindly do the needful...

3 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 15 Oct 2013, 11:34 AM
Hello,

Please try with the below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource" OnItemDataBound="RadGrid1_ItemDataBound">
               <MasterTableView DataKeyNames="ID">
                   <Columns>
                       <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"></telerik:GridBoundColumn>
                       <telerik:GridTemplateColumn Display="false">
                           <ItemTemplate>
                               <asp:Label runat="server" ID="lblRowStyle"></asp:Label>
                           </ItemTemplate>
                       </telerik:GridTemplateColumn>
                   </Columns>
               </MasterTableView>
           </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
   {
       DataTable dt = new DataTable();
       dt.Columns.Add("ID", typeof(int));
       dt.Columns.Add("Name", typeof(string));
       dt.Rows.Add(1, "name1");
       dt.Rows.Add(2, "name2");
       dt.Rows.Add(3, "name3");
       RadGrid1.DataSource = dt;
   }
   protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = e.Item as GridDataItem;
            
           Label lblRowStyle = item.FindControl("lblRowStyle") as Label;
           lblRowStyle.Attributes.Add("MyID",item.GetDataKeyValue("ID").ToString()); // Using dataKey
           lblRowStyle.Attributes.Add("MyName",(item.DataItem as DataRowView)["Name"].ToString()); // Using DataItem
       }
   }



Thanks,
Jayesh Goyani
0
Zakir
Top achievements
Rank 1
answered on 15 Oct 2013, 12:04 PM

Hi Jayesh,

Thanks for yur quick reply..

Currently i am doing from code behind.

is there any another solution without code behind?
Is it possible to directly bind the data with custom data attribute?

0
Kostadin
Telerik team
answered on 18 Oct 2013, 06:56 AM
Hello Zakir,

I would recommend you to examine the grid's documentation which demonstrates a different binding solution. The aforementioned help article describes which type of data sources could be bound declarative.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Zakir
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Zakir
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or