EDITED QUESTION
I want to pass a variable, in this case 'name' containing the string bill, to a code behind method and use debug.print to see it
string name = "bill";
<asp:ImageButton runat="server" id="DeleteButton" ImageUrl="Images/delete.jpg"
CommandArgument='<%# Eval("name") %>' CommandName="ThisBtnClick" text="Delete Me" onclick="DeleteMonth" />
I've tried:
CommandArgument='<%# Eval("name") %>'
CommandArgument='<%# Bind("name") %>'
CommandArgument='<%= "name" %>
This is my print function
protected void DeleteMonth(object sender, EventArgs e)
{
ImageButton btn = (ImageButton)sender;
switch (btn.CommandName)
{
case "ThisBtnClick":
Debug.Print("--" + btn.CommandArgument.ToString());
break;
case "ThatBtnClick":
break;
}
}
I think i need to databind something first but honestly I have no idea. I just get a blank when i print. Has anyone dealt with this before
EDIT
What I want to do is dynamically create a table. the name variable gets pulled from a database and then creates a table based on that name. I want the last column of the table to be an X so i can delete everything in that row. I'm using an imagebutton. here's my code
using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(sqlConnectionString))
{
conn.Open();
string query = "SELECT * FROM dbo.Archive";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query, conn);
System.Data.SqlClient.SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
string name, created, 1Updated, 2Updated, 3Updated;
name = rdr.GetString(1); // name of month
if (!(rdr.IsDBNull(2))) // checks date for a null value
{ created = rdr.GetDateTime(2).ToString(); }// if not null date is turned into a string and saved in a variable
else
{ created = "---"; } // else date is given a default value
if (!(rdr.IsDBNull(3)))
{ 1Updated = rdr.GetDateTime(3).ToString(); }
else
{ 1Updated = "---"; }
if (!(rdr.IsDBNull(4)))
{ 2Updated = rdr.GetDateTime(4).ToString(); }
else
{ 2Updated = "---"; }
if (!(rdr.IsDBNull(5)))
{ 3Updated = rdr.GetDateTime(5).ToString(); }
else
{ 3Updated = "---"; }
Response.Write("<tr><td>" + name + "</td>");
Response.Write("<td>" + created + "</td>");
Response.Write("<td>" + 1Updated + "</td>");
Response.Write("<td>" + 2Updated + "</td>");
Response.Write("<td>" + 3Updated + "</td>");
Response.Write("<td><a>1</a></td>");
Response.Write("<td><a>2</a></td>");
Response.Write("<td><a>3</a></td>");
Response.Write("<td><a>Compliance Summary</a></td>");
Response.Write("<td align = 'center'>"+name);%>
<asp:ImageButton runat="server" id="DeleteButton" ImageUrl="Images/delete.jpg"
CommandArgument='<%# Eval("name") %>' CommandName="ThisBtnClick" text="Delete Me" onclick="DeleteMonth" />
<% Response.Write("</td></tr>");
}
Use like this......
<asp:ImageButton runat="server" id="DeleteButton" ImageUrl="Images/delete.jpg"
CommandArgument='<%# Eval("UserName")%>' text="Delete Me" onclick="DeleteMonth" />
protected void DeleteMonth(object sender, EventArgs e)
{
**ImageButton btn = ((ImageButton)sender).CommandArgument;**
switch (btn.ToString())
{
case "ThisBtnClick":
Debug.Print("--" + btn.CommandArgument.ToString());
break;
case "ThatBtnClick":
break;
}
}
Use CommandArgument='<%#Eval("name")%>'
instead of CommandArgument="<%Response.Write(name);%>"
EDIT
Aren't you using Data control like GridView, FormView or DataList? if not you have to use one of those in order to use Eval method. As a example of GridView you have to bind GridView datasource first.
http://msdn.microsoft.com/en-us/library/aa479353.aspx
OR
Declare public properties for your DB fields.
How can I use Eval in asp.net to read fields from a database?
The Eval method takes the name of a data field and returns a string containing the value of that field from the current record in the data source.
Related
I have a gridview with the Template and it contains a LinkButton. When I click the button I want to open a link in new tab
<Templates>
<Obout:GridTemplate runat="server" ID="tempCurrTask">
<Template>
<asp:LinkButton Text='<%# Container.DataItem["CurrentTask"] %>' ID="lnkbtnview2"
runat="server" Font-Underline="true" OnCommand="SELREC" CommandArgument='<%# Container.PageRecordIndex %>'></asp:LinkButton>
</Template>
</Obout:GridTemplate>
And the SELREC function is
protected void SELREC(object sender, CommandEventArgs e)
{
int rowIndex = int.Parse(e.CommandArgument.ToString());
Hashtable dataItem = grvLeads.Rows[rowIndex].ToHashtable() as Hashtable;
string id = Convert.ToString(dataItem["iTask_id"]); //.Split('|');
string rowIndexid = id.ToString();
//+ "/" + e.CommandName.ToString();
//ScriptManager.RegisterStartupScript(this, typeof(string), "openWindow", "window.open('Task.aspx?TaskID=" + rowIndexid.Trim() + "', '_newtab','left = 10, top=10,scrollbars=Yes,resizable=yes,width=1100,height=580'); ", true);
Response.Redirect("Task.aspx?TaskID=" + rowIndexid.Trim());
}
This link opens in the same tab. I want it to open in new tab, So I changed the asp:LinkButton to asp:HyperLink tag but the SELREC function is not called properly. I want to do it using LinkButton and I don't know how to do it by using the link button. So please anybody help me with sample code.
Try this approach;
<asp:LinkButton runat="server" href='<%# "Task.aspx?TaskID=" + MethodtoGenerateTaskId(parameter) %>' target="_blank">LinkButton</asp:LinkButton>
You should define MethodtoGenerateTaskId(parameter) in c# codebehind. Take CommandArgument as a parameter to this method.
protected string MethodtoGenerateTaskId(string command_arg)
{
int rowIndex = int.Parse(command_arg.ToString());
Hashtable dataItem = grvLeads.Rows[rowIndex].ToHashtable() as Hashtable;
string id = Convert.ToString(dataItem["iTask_id"]); //.Split('|');
string rowIndexid = id.ToString();
return rowIndexid.Trim();
}
and in markup;
<asp:LinkButton runat="server" href='<%# "Task.aspx?TaskID=" + MethodtoGenerateTaskId(Container.PageRecordIndex.ToString()) %>' target="_blank">LinkButton</asp:LinkButton>
and if it works; pls mark it as answer...
I want to bind a Hidden Field because I want to pass a value from code behind to the asp:Parameter Name="HOME_TEAM_COACH_ID" Type="Int32".
My asp:
<asp:FormView ID="FormView1" runat="server" OnItemUpdated="FormView1_ItemUpdating" >
<EditItemTemplate>
HOME_TEAM:
<asp:DropDownList ID="DropDownListHometeam" runat="server"
DataSourceID="SqlDataGetTeams"
DataTextField="NAME" DataValueField="ID" SelectedValue='<%# Bind("HOME_TEAM_ID") %>'>
</asp:DropDownList>
<asp:HiddenField runat="server" ID="testLabel" Value='<%# Bind("HOME_TEAM_COACH_ID") %>' />
</EditItemTemplate>
And c# behind is:
protected void FormView1_ItemUpdating(object sender, FormViewUpdatedEventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Edit)
{
DropDownList HomeTeamId = FormView1.FindControl("DropDownListHometeam") as DropDownList;
string team = string.Format("{0}", HomeTeamId.Text);
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BasketballConnectionString1"].ToString());
conn.Open();
string queryHome = "SELECT dbo.COACH.ID, dbo.COACH.SURENAME FROM dbo.COACH INNER JOIN dbo.GAMES ON dbo.COACH.TEAM_ID = dbo.GAMES.HOME_TEAM_ID WHERE (dbo.GAMES.HOME_TEAM_ID =" + team + ")";
SqlCommand cmd = new SqlCommand(queryHome, conn);
var Home_Coach_Id = cmd.ExecuteScalar().ToString();
HiddenField HomeCoachIdLabel = FormView1.FindControl("testLabel") as HiddenField;
HomeCoachIdLabel.Value = Convert.ToString(Home_Coach_Id);
conn.Close();
I want Help with the last four lines where I want to pass the Home_Coach_Id value to bind the asp:HiddenField ID="testLabel" Value='<%# Bind("HOME_TEAM_COACH_ID") %>'.
When I click update, it doesn't change the value in database. (When I debug, in the last lines it gives me the correct HomeCoachIdLabel.Value.)
any suggestions?
You do not need the explicitly set the HiddenField's Value property, because it is done by the <%# Bind("HOME_TEAM_COACH_ID") %> in your markup.
I believe your problem is that you are not returning the HOME_TEAM_COACH_ID from your query to the database in your SELECT statement:
SELECT dbo.COACH.ID, dbo.COACH.SURENAME FROM dbo.COACH
INNER JOIN dbo.GAMES ON dbo.COACH.TEAM_ID = dbo.GAMES.HOME_TEAM_ID
WHERE (dbo.GAMES.HOME_TEAM_ID =" + team + ")
The problem is that it needs the method prerender and not the method onitemupdated.
asp:FormView ID="FormView1" runat="server" OnPreRender="FormView1_OnPreRender" >
and also in c#
protected void FormView1_OnPreRender(object sender, FormViewUpdatedEventArgs e)
{
It also works when I put it in page load{ }.
The next step is to make the insert event....
I want to pass all the gridview value into another page
I have one gridview in PatientDetails.aspx page and one button as below
<asp:GridView ID="gvDoctorList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
AllowPaging="True" AllowSorting="True" AutoGenerateEditButton="true" AutoGenerateSelectButton="true"
AutoGenerateDeleteButton="true" OnSelectedIndexChanged="gvDoctorList_SelectedIndexChanged" OnRowCommand="gvDoctorList_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="chk" OnCheckedChanged="chk_CheckedChanged" AutoPostBack="true" />
<asp:Label runat="server" ID="lblPID" Visible="false" Text='<%# Eval("PatientId") %>'></asp:Label>
<asp:Button ID="btnSelect" runat="server" Text="Select" CommandName = "Select" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="PatientId" HeaderText="PatientId" SortExpression="PatientId" />
<asp:BoundField DataField="firstname" HeaderText="firstname" SortExpression="firstname" />
<asp:BoundField DataField="lastname" HeaderText="lastname" SortExpression="lastname" />
<asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDatabaseConnectionString %>"
SelectCommand="SELECT [PatientId],[firstname], [lastname], [sex] FROM [PatientDetails]"></asp:SqlDataSource>
<asp:Button ID="btnformatric" runat="server" Text="formatric3d" OnClick="btnformatric_Click" OnCommand="btnformatric_Command" />
on codebehind of PatientDetails.aspx is as below
protected void btnformatric_Click(object sender, EventArgs e)
{
if (gvDoctorList.SelectedRow != null)
{
Server.Transfer("Patientstaticformatrix.aspx");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please select a row.')", true);
}
}
Now on the second page name Patientstaticformatrix.aspx the code behind is as below
protected void Page_Load(object sender, EventArgs e)
{
if (this.Page.PreviousPage != null)
{
GridView gvDoctorList = (GridView)this.Page.PreviousPage.FindControl("gvDoctorList");
GridViewRow selectedRow = gvDoctorList.SelectedRow;
Response.Write("PatientId: " + selectedRow.Cells[0].Text + "<br />");
Response.Write("firstname: " + selectedRow.Cells[1].Text + "<br />");
Response.Write("lastname: " + selectedRow.Cells[2].Text + "<br />");
}
}
I had debug the code in second page....the value for gvDoctorList is null as well as the selectedRow is showing error of nullreference.
Can you please let me where I am wrong?
As i have seen your previous question also, So i can suggest you one thing, rather than keeping your gridview in session(which is expensive) you can use RowCommand event, and after having button here i don't think you need checkbox or chk_CheckedChanged event, you can pass the PatientID to your next page there you can write query to insert selected row data to your new table.
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox runat="server" ID="chk" OnCheckedChanged="chk_CheckedChanged"
AutoPostBack="true" />
<asp:Label runat="server" ID="lblPID" Visible="false" Text='<%# Eval("PatientId") %>'>
</asp:Label>
<asp:Button ID="btnSelect" runat="server" Text="Select" CommandArgument='<%#
Eval("PatientId") %>' CommandName = "Select" />
</ItemTemplate>
</asp:TemplateField>
protected void gvDoctorList_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "select")
{
int pID = Convert.ToInt32(e.CommandArgument);
// either put ID in session and check
Session["PatientID"] = Convert.ToString(pID);
Server.Transfer("Patientstaticformatrix.aspx");
}
}
On page_Load Event
protected void Page_Load(object sender, EventArgs e)
{
string pID = Convert.ToString(Session["PatientID"]);
if(!string.IsNullOrEmpty(pID))
{
int patientID = Convert.ToInt32(pID);
//Call Stored procedure which will insert this record with this ID
// to another table
}
}
Try using Session Variables. You can set the GridView into a Session variable that can then be retreived later so long as the same session is still active.
You can use the following code to set the Session Variable on your first page :
Session["gvDoctorList"] = gvDoctorList;
And then to retreive from the variable on your second page :
GridView gvDoctorList = (GridView)Session["gvDoctorList"];
For more information on Sessions see the MSDN Session State Overview.
I have decided to add a second answer based on the correct comments from Ahmed, The session variables really shouldn't hold the amount of data of the gridview due to memory issues.
The following should work accordingly for what I assume you are doing :
Essentially when you are selecting the row to go to the next page you are trying to retrieve the data of that row onto the new page. Is this Assumption correct? If so then you have a number of options for you to use.
Again you could use the Session Variables to store the data of the row once extracted on the first page :
protected void btnformatric_Click(object sender, EventArgs e) {
if (gvDoctorList.SelectedRow != null) {
GridViewRow selectedRow = gvDoctorList.SelectedRow;
Session["PatientId"] = selectedRow.Cells[0].Text;
Session["firstname"] = selectedRow.Cells[1].Text;
Session["lastname"] = selectedRow.Cells[2].Text;
Server.Transfer("Patientstaticformatrix.aspx");
} else {
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please select a row.')", true);
}
}
Essentially here you are on the first page and you get the data from the row. You then store this data in session variables and you can use the following to find the data from the next page :
protected void Page_Load(object sender, EventArgs e) {
if (this.Page.PreviousPage != null) {
//Retrieve values from Session Variables
Response.Write("PatientId: " + Session["PatientId"].ToString() + "<br />");
Response.Write("firstname: " + Session["firstname"].ToString() + "<br />");
Response.Write("lastname: " + Session["lastname"].ToString() + "<br />");
}
}
You also have a second option of using Query Strings to pass the data. Although for this method I believe you will have to change the Server.Transfer("Patientstaticformatrix.aspx"); to be Response.Redirect("Patientstaticformatrix.aspx");
Below is an example on using Query Strings :
protected void btnformatric_Click(object sender, EventArgs e) {
if (gvDoctorList.SelectedRow != null) {
GridViewRow selectedRow = gvDoctorList.SelectedRow;
//Create URL with Query strings to redirect to new page
Response.Redirect("Patientstaticformatrix.aspx?parentid=" + selectedRow.Cells[0].Text + "&firstname=" + selectedRow.Cells[1].Text + "&lastname=" + selectedRow.Cells[2].Text);
} else {
ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please select a row.')", true);
}
}
And to retrieve the values from the Request.QueryString object on the second page.
protected void Page_Load(object sender, EventArgs e) {
if (this.Page.PreviousPage != null) {
//Retrieve values from Query Strings
Response.Write("PatientId: " + Request.QueryString["parentid"].ToString() + "<br />");
Response.Write("firstname: " + Request.QueryString["firstname"].ToString() + "<br />");
Response.Write("lastname: " + Request.QueryString["lastname"].ToString() + "<br />");
}
}
Both of these solutions should meet your requirements, however they are both slightly different. The Session Variable solution is probably the preferred method as it will stop users from being able to see all of the data passed (if you need to pass confidential information) where as the Query String values will be available to anyone who can see the URL.
For more information on Session Variables and Query Strings see the below resources :
ASP.NET Session State Overview
Request.QueryString Collection
#Nunners answer is ownsome, but can also try with following way:
on anothoer page's pageload event fetch grid like:
GridView GridView1 = (GridView)this.Page.PreviousPage.FindControl("GridView1");
All the technique is given below:
http://www.aspsnippets.com/Articles/Pass-Selected-Row-of-ASPNet-GridView-control-to-another-Page.aspx
Refer above doccument.
The real answer is that you should create the same gridview on another page. This is how 99% of ASP.NET sites work since that page at some point will be writing/updating/deleting data. Or just use the same page - why redirect to show the same data?
I found some solution:
In Source aspx after grid databind:
Session["gridtoexcel"] = yourgrid;
In destination aspx
var grid = ((GridView)Session["gridtoexcel"]);
gridToExcel.Columns.Clear();
foreach (DataControlField col in grid.Columns)
gridToExcel.Columns.Add(col);
gridToExcel.DataSource = grid.DataSource;
gridToExcel.DataBind();
this way i can 'clone' exact grid to another page. if you need some css style don't forget of add them in destination page
PS: gridToExcel is your destination grid
The quantity (quantityWanted in DB) in textbox is loaded via Eval() method from Basket DB table. What I want to achieve is that when I change quantity manually and click update the quantity for that record will be updated and then grid will be reloaded. I seem unable to retrieve value of that textbox in code behind.
I am aware of FindControl() method which is used to get value from controls within itemtemplate but I don't know how to use it here.
The tried below but always get nullReferenceException
TextBox txt = (TextBox)GridView2.FindControl("txtQuantityWanted");
int _quantity = Convert.ToInt16(txt.Text);
Note: button is there but does nothing.
<ItemTemplate>
<asp:TextBox runat="server" ID="txtQuantityWanted" Text='<%# Eval("quantityWanted") %>' ></asp:TextBox>
<asp:LinkButton ID="LinkButton11" runat="server" CommandName="update" CommandArgument='<%# Eval("coffeeName") + ";" + Eval("datetimeAdded") %>' >Update</asp:LinkButton>
<asp:Button ID="Button21" runat="server" Text="Button" CommandName="edit" />
</ItemTemplate>
<asp:TemplateField HeaderText="Total [£]">
<ItemTemplate>
<asp:Label id="lblItemTotal" runat="server" Text='<%# String.Format("{0:C}", Convert.ToInt32(Eval("quantityWanted"))* Convert.ToDouble(Eval("price"))) %>' ></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="remove" CommandArgument='<%# Eval("coffeeName") + ";" + Eval("datetimeAdded") %>' >Remove</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
C# code:
protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
{
// .....
else if (e.CommandName == "update")
{
string params = Convert.ToString(e.CommandArgument);
string[] arg = new string[2];
arg = params.Split(';');
name = Convert.ToString(arg[0]);
datetimeAdded = Convert.ToString(arg[1]);
const string strConn = #"Data Source=.\SQLEXPRESS;AttachDbFilename=L:\ASP.NET\Exercise1\Exercise1\Exercise1\App_Data\ASPNETDB.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True";
DataSet ds = new DataSet("Employees");
SqlConnection connection = new SqlConnection(strConn);
// Here I need value from textbox to replace 11
SqlCommand abc = new SqlCommand("UPDATE Basket SET quantityWanted = 11 WHERE coffeeName LIKE '%" + name + "%' AND datetimeAdded LIKE '" + datetimeAdded + "' ", connection);
connection.Open();
int ii = abc.ExecuteNonQuery();
connection.Close();
}
}
Use GridView.Rows collection to find control. You can pass the index of row in rows collection indexer.
TextBox txt = (TextBox)GridView2.Rows[0].FindControl("txtQuantityWanted");
You must pass the row index as well,Your code will look like this
TextBox txt = (TextBox)GridView2.Rows[0].FindControl("txtQuantityWanted");
I hope it will work for you.
Control ctrl = e.CommandSource as Control;
if (ctrl != null)
{
GridViewRow gvRow = ctrl.Parent.NamingContainer as GridViewRow;
TextBox txt= (TextBox)gvRow.FindControl("txtQuantityWanted");
}
I need to add an specific text in an itemtemplate on a gridview...
right now I have this in my gridview
<asp:TemplateField HeaderText="Total" SortExpression="Total" ItemStyle-Width="100px">
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server" Text='<%#Math.Round(Convert.ToDouble(Eval("Total")), 2).ToString("C") + " M.N."%>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
in the part where it says
<asp:Label ID="lblTotal" runat="server" Text='<%#Math.Round(Convert.ToDouble(Eval("Total")), 2).ToString("C") + " M.N."%>'>
I made an specific text, but it will always be the same text (well except in the Eval of course)... But I need to get the format I need from this method.
public static string GetFormatoMoneda(decimal decCantidad)
{
//Get data from currency (Dollars, Pesos, Euros, etc.)
DataRow dr = ConexionBD.GetInstanciaConexionBD().GetTipoDeMonedaPrincipal((int)HttpContext.Current.Session["Grupo"]);
return dr["Signo"] + Math.Round(decCantidad, 2).ToString("C").Substring(1) + " " + dr["Abreviatura"];
}
I use this method to get a specific string and use it on labels (I assign it on code on the cs file)..
But in this case... I have to insert that text on the column of a gridview...
How can I get that string value and insert it on a label inside of a templatefield/itemtemplate??
Instead of ...
Text='<%#Math.Round(Convert.ToDouble(Eval("Total")), 2).ToString("C") + " M.N."%>'
...use
Text='<%#GetFormatoMoneda(Eval("Total"))%>'
However, this assumes that GetFormatoMoneda is in the same class as the web form. If not, then you need to include the class name, e.g.
Text='<%#MyClass.GetFormatoMoneda(Eval("Total"))%>'
Then you either need to make a change to GetFormatoMoneda to use an object type parameter, e.g.
public static string GetFormatoMoneda(object objCantidad)
{
var decCantidad = Convert.ToDecimal(decCantidad);
//Get data from currency (Dollars, Pesos, Euros, etc.)
DataRow dr = ConexionBD.GetInstanciaConexionBD().GetTipoDeMonedaPrincipal((int)HttpContext.Current.Session["Grupo"]);
return dr["Signo"] + Math.Round(decCantidad, 2).ToString("C").Substring(1) + " " + dr["Abreviatura"];
}
or use another method with an object parameter and call GetFormatoMoneda(decimal), passing in the correct value, such as
protected string CorrectFormat(object obj)
{
return GetFormatoMoneda(Convert.ToDecimal(obj));
}
in which case you would use
Text='<%#CorrectFormat(Eval("Total"))%>'
If you wanted to do it programmatically, this would work:
Default.aspx:
<asp:GridView ID="gvGrid" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvGrid_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblTotal" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Generate fake data
var data = Enumerable.Range(1, 20);
//Give the data to the grid
gvGrid.DataSource = data;
gvGrid.DataBind();
}
}
protected void gvGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Find the control
var lblTotal = (Label)e.Row.FindControl("lblTotal");
//Get the data for this row
var data = (int)e.Row.DataItem;
//Display the data
lblTotal.Text = data.ToString();
}
}