Template field in Grid

3 posts, 0 answers
  1. ithihas
    ithihas avatar
    14 posts
    Member since:
    Jun 2012

    Posted 12 Apr 2012 Link to this post

    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. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 12 Apr 2012 Link to this post

    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.
  3. ithihas
    ithihas avatar
    14 posts
    Member since:
    Jun 2012

    Posted 12 Apr 2012 Link to this post

    its working. thankssssssssssssssss
Back to Top