This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14275|Reply: 0

[ASP.NET] GridView data binding

[Copy link]
Posted on 4/8/2015 10:49:14 PM | | |

There are two ways to bind GridView data: one is automatic binding, and the other is manual binding. Automatic binding is not mentioned here, mainly explaining the steps and methods of manual binding
First, add the GridView object to the foreground page, and then go to the background
     Add a data source
      this.gvShowTenementsInfo.DataSource = tenementService.Select();
      Bind data sources
      this.gvShowTenementsInfo.DataBind();
Perform background data binding
After that, go to the source interface of the front desk page
Edit between <asp:GridView ID="gvShowTenementsInfo" runat="server"> and </asp:GridView> to manually add the columns that need to be showcased.
//这里是展示的集合
<Columns>
The HeaderText of the binding display data displays the header description field, and the DataField after it is used to bind the specific data source and display the data
         <asp:BoundField HeaderText="Household Name" DataField="tenName" />
  Here, ItemStyle-HorizontalAlign selects the arrangement style within the specific data column, such as centering, which needs to be manually added to each row
          <asp:TemplateField HeaderText="Whether to edit" ItemStyle-HorizontalAlign="Center">
            <ItemTemplate>
    Here is the setting method in the template page, binding as many columns as you need
            <asp:Label ID="txtShow" runat="server" Text='<%# eval_r("tenName") %>' />
            </ItemTemplate>
          </asp:TemplateField>
          <asp:TemplateField HeaderText="whether to edit" >
            <ItemTemplate>
                Here is passing the object ID to be modified to the next page (Modify update page)
               <a href='UpdateTenementTypeInfo.aspx? id=<%# eval_r("tenId") %>'> edit</a>
            </ItemTemplate>
          </asp:TemplateField>
        </Columns>




Previous:Exception details: System.NullReferenceException: The object reference is not set to the instance of the object.
Next:DataTable extracts the data from the first row
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com