VKinfotek Inc.
  • Us
    About Us
    Contact Us
  • FAQs
  • Ready Software
    Ready ERP ASP Core Software for Azure Cloud
    Ready Web ERP Software
    Ready ASP.Net Azure Software
    Ready C# SQL Server Accounting Software
    Ready ASP.Net MVC and EF Software
First slide
Earn $100/hour in USA! Click Here

How to access DetailsView's fields programmatically

To display data in a DetailsView control, we use BoundField elements or TemplateField elements. This example demonstrates how to access field's values of a DetailsView control programmatically, when we have created DetailsView control using BoundField elements.

When a DetailsView control displays data, each row corresponds to a BoundField. We know that the DetailsView control renders each field of a record as a table row.

The Rows[0] indicates the first field and Rows[1] indicates the second field and DetailsView renders a cell with a textbox in it.

<asp:DetailsView ID="DetailsView1" runat="server"   
   AllowPaging="true" DataKeyNames="Code" 
   DataSourceID="MyDataSource"    AutoGenerateRows="false" 
     OnDataBound="DetailsView1_DataBound"
   AutoGenerateInsertButton="true" 
   
   AutoGenerateEditButton="true">
   <Fields>
   
   <asp:BoundField  DataField="Name" HeaderText="Name" />
   <asp:BoundField  DataField="description" HeaderText="description" />
   
   </Fields>
   
   </asp:DetailsView>
<asp:SqlDataSource ID="MyDataSource"  
ConnectionString="<%$Connectionstrings:ERPConnectionString%>"
SelectCommand="SELECT * FROM Sample" 
UpdateCommand="Update SAMPLE SET Name=@Name,description=@description Where Code=@Code"
DeleteCommand="Delete SAMPLE Where Code=@Code" 
InsertCommand="Insert SAMPLE(Code,Name,description) VALUES(@Code,@Name,@description)"
runat="server"/>


output of DetailsView control

The following code example demonstrates how to use the DataBound event handler to access programmatically the bound fields in a DetailsView control. The below code works only when DetailsView control uses the BoundField element. We cannot apply the same logic when we are using Template fields.

protected void DetailsView1_DataBound(object sender, EventArgs e)
{
    string description=DetailsView1.Rows[1].Cells[1].Text;
}


DetailsView Articles
  • Difference between DetailsView and FormView control
  • DataBinding a DetailsView control
  • GridView and DetailsView Master/Detail page using SqlDataSource control
  • GridView and DetailsView master detail page using ObjectDataSource control
  • DropDownList and GridView Master/Detail page using ObjectDataSource control
  • DetailsView databound event
  • DetailsView integer type conversion error?
  • Using detailsview control datakeynames property
  • How to get the datakey value in DetailsView control
  • DetailsView autogeneraterows property
  • DetailsView fields
  • Formatting DetailsView control with style properties
  • Using Boundfields in DetailsView control
  • Display message using EmptyDataTemplate in the DetailsView Control
  • Bind a DetailsView control with a DropDownList control
  • Using Command buttons in DetailsView control
  • Using Commandfield element in a DetailsView control
  • Using buttonfield in a DetailsView control
Most Viewed

Azure Q & A
Azure Platform
Grid-View
GridView CommandField example
Details-View
GridView and DetailsView Master/Detail page using SqlDataSource control
POCO
POCO overview and advantages - POCO class, Entity Framework in Enterprise Applications
Entity Framework
Query entity data model using linq to entities
Array List
Difference between arraylist and list collection
Web Services
How to create a Web service using Visual Studio.net
Form-View
FormView DataBound Event
Object Oriented Programming
Calling base class constructor in C#
Linq
Convert a sequence to a generic list using ToList()method
ERP
ERP Software Development
Project Ideas
Project ideas for students
AccountingSoftware
Accounting Software
MVC
Creating an ASP.Net MVC 3 application
.Net
Using assemblies in .net applications
ASP .Net
How to implement form validation using ASP.Net 2.0 Validation Controls


  • SITEMAP
  • Terms of use
  • Testimonials

Back to top

Copyright © 2016 - All Rights Reserved - VKInfotek.com