what difference between gridview and data bound
what difference between gridview and data bound
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jul 13, 2012, 8:04 AM
Can you please provide more info about your question.
I can not get your question.
thx.
Satyapriya NayakPosted Jul 13, 2012, 7:58 AM
We use gridview databound event when we want to do certain things after the server controls bind to the datasource. For example after the binding we may want to display some text at the bottom of the grid or we might want to calculate the total value of a column.
Here is the example of how to use gridview databound event.
THIS IS AN ASPX FILE:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DGridview.aspx.cs" Inherits="_DGridview" %>
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>GridView Demotitle>
head>
<body>
<form id="form1" runat="server">
<div>
<h1>GridView Demoh1>
<asp:GridView ID="GridDataBound" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
<asp:BoundField DataField="MarksInMaths" HeaderText="MarksInMaths"
SortExpression="MarksInMaths" />
<asp:BoundField DataField="MarksInEnglish" HeaderText="MarksInEnglish"
SortExpression="MarksInEnglish" />
<asp:BoundField DataField="MarksInScience" HeaderText="MarksInScience"
SortExpression="MarksInScience" />
<asp:BoundField DataField="TotalMarks" HeaderText="TotalMarks"
SortExpression="TotalMarks" />
<asp:BoundField DataField="ObtainedMarks" HeaderText="ObtainedMarks"
SortExpression="ObtainedMarks" />
Columns>
asp:GridView>
div>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="GetStudents" TypeName="QVISLib.SampleData">
asp:ObjectDataSource>
form>
body>
html>
THIS IS THE CODE FILE:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _DGridview : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Create a new databound event
GridDataBound.DataBound += new EventHandler(GridDataBound_DataBound);
}
void GridDataBound_DataBound(object sender, EventArgs e)
{
GridDataBound.ShowFooter = true;
//Remove un-use GridDataBound
for (int i = GridDataBound.Columns.Count - 1; i > 0; i--)
{
GridDataBound.FooterRow.Cells.RemoveAt(i);
}
GridDataBound.FooterRow.Cells[0].ColumnSpan = GridDataBound.Columns.Count;
GridDataBound.FooterRow.Cells[0].HorizontalAlign = HorizontalAlign.Center;
GridDataBound.FooterRow.Cells[0].Text = "This is an example of data bound event";
}
}
Please refer the below links
http://www.itjungles.com/dotnet/gridview-databound-event
Thanks