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

Template field in Grid

2 Answers 311 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
ithihas
Top achievements
Rank 1
ithihas asked on 12 Apr 2012, 08:52 AM
how can i load data read from database to a textbox template field in gridview. Please help me to solve this as soon as possible.
Thanks..................

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Apr 2012, 10:09 AM
To Pradeep Chand,

Here is the two methods to bind data into a TextBox.

ASPX:
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" DataSourceID="sqlDataSource2" runat="server" onitemdatabound="RadGrid1_ItemDataBound">
  <MasterTableView >
    <Columns>
      <telerik:GridTemplateColumn>
        <ItemTemplate>
          <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("LastName") %>'></asp:TextBox> // binding textbox in aspx
      <asp:TextBox ID="TextBox3" runat="server" ></asp:TextBox>
     </ItemTemplate>
       </telerik:GridTemplateColumn>
    </Columns>
  </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
  if (e.Item is GridDataItem)
    {
       GridDataItem ditem = (GridDataItem)e.Item;
       TextBox txtBox = e.Item.FindControl("TextBox3") as TextBox;
       txtBox.Text=(string)DataBinder.Eval(e.Item.DataItem, "FirstName").ToString(); // Binding in code behind
     }
}

Thanks,
Shinu.
0
ithihas
Top achievements
Rank 1
answered on 12 Apr 2012, 11:44 AM
its working. thankssssssssssssssss
Tags
General Discussions
Asked by
ithihas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
ithihas
Top achievements
Rank 1
Share this question
or