CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2001
    Location
    Denmark
    Posts
    453

    Question Getting data from BoundField by name

    For templatefields, I can get data from a textbox in my GwRowUpdating function by

    obj.Name = ((TextBox)(GridView1.Rows[e.RowIndex].FindControl("TxtName"))).Text.Trim();

    And I've seen people getting data from BoundFields by

    TextBox txtBox = (TextBox)GridView1.Rows[GridView1.EditIndex].Controls[6];

    This works fine as long as you don't change the order of the columns. I would much rather be able to do something like

    TextBox txtBox = (TextBox)GridView1.Rows[GridView1.EditIndex].Controls["Name"];

    when getting data from
    <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />

    But it seems I can only use an index no rather than a text like for instance connection strings

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Getting data from BoundField by name

    Why not consider a different approach? Rather than reading the data from the columns/rows in the control, why not access the data from the datasource directly? If you are returning table data from a db, create a concrete object to store the data and map the data from the table, and put the object into a collection. Then bind the collection to the grid.

    Do all your operations (insertions, deletions, updates, etc.) on the collection and rebind it to the control. Do all your sorting operations on the collection as well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured