Asp Gridview use Boundfields? or Templatefields?
Asked Answered
T

3

6

I put data in a data table e.g.

dt.TableName = "SA1";
da.Fill(dt);

GridView1.DataSource = dt;
GridView1.DataBind();

Now I'm not sure if I should use boundfield (For all columns)

<asp:BoundField DataField="Unit" HeaderText="Unit" SortExpression="Unit"  />

or use

<asp:TemplateField>
    <HeaderTemplate>
        Units
    </HeaderTemplate>
    <ItemTemplate>
        <asp:TextBox runat="server" ID="txbUnits" Text='<%# Eval("Unit")%>'></asp:TextBox>
    </ItemTemplate>
</asp:TemplateField>

and add the data as i go along, the gridview's purpose is only to display data

Thesis answered 22/4, 2014 at 12:4 Comment(0)
C
14

If you want to display rows without anything fancy, or any particular design, you would use BoundField. However if you would like to design the displaying of the record in a different manner than the default - you would need to create your own row template, by using the TemplateField.

Check out these links - they briefly explain the differences, but it is basically default VS customised presentation. http://forums.asp.net/t/1369418.aspx?boundfield+vs+template+field+in+gridview http://www.c-sharpcorner.com/Interviews/answer/1751/difference-between-boundfield-and-templatefield

Congruous answered 22/4, 2014 at 12:7 Comment(2)
I want to use BoundField for some reason, but Can I will be able to Edit things when I needed with boundField ?Definitely
Yes you can. You can find an example here #12221555Congruous
N
4

If you want to just display the data then you should use bound field attribute.

Nacelle answered 22/4, 2014 at 12:6 Comment(0)
T
1
  • The BoundField displays the value of specified DataSource field as text.
  • The TemplateField allows for a mix of HTML markup, Web controls, and data-binding syntax.

    Your purpose is only to display data.So i think you need BoundField Here

Table answered 22/4, 2014 at 12:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.