IN My application i am using grid, and binging the grid with list, and in the i applying 2 events selected index changed and pageindex changing event when i am clicking on a footer page index it is working and when i am trying to click on the second time it causes the following error and if try to select a record by clicking on select button also it causes the same error
please check this error and post the comments or mistakes in it
if you want the code
AllowPaging="true" onpageindexchanging="gvInvoiceslist_PageIndexChanging">
.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LOSIMSystem.BLL.Controllers;
namespace LOSIMSystem.Admin
{
public partial class InvoiceArchieved : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindInvoicesToGrid();
}
private void BindInvoicesToGrid()
{
InvoiceController invctrl = new InvoiceController();
gvInvoiceslist.DataSource = invctrl.GetAllInvoices();
gvInvoiceslist.DataBind();
}
protected void ViewInvoiceByRefId(object sender, EventArgs e)
{
int srowindex = gvInvoiceslist.SelectedIndex;
int refid =Convert.ToInt16(((HiddenField)gvInvoiceslist.Rows[srowindex].FindControl("hdnrefid")).Value);
InvoiceController invoicectrl = new InvoiceController();
Common.BussinessObjects.BLInvoice blinvoice= invoicectrl.GetInvoice(refid);
Response.Redirect("viewinvoice.aspx?hiddenid=" + refid);
}
protected void gvInvoiceslist_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvInvoiceslist.PageIndex = e.NewPageIndex;
}
}
}
Amit ChoudharyPosted Feb 18, 2010, 2:48 AM
i have doubt on the following line:
you want to use InvoiceRefID as your unique id associated to your rows.
I suggest you to use DataKey property of gridview instead of Hidden Field. Hope it may solve your problem.
assign Datakey="InvoiceRefID"
syntax to find a datakey in a gridview:
Hope it helps.
Don't forget to mark as answer if it help you
SivaRamaKrishna RajuPosted Feb 18, 2010, 2:30 AM
thanks for your advise and here ai am pasting error
Server Error in '/' Application.
An error has occurred because a control with id 'ctl00$cphContent$gvInvoiceslist$ctl07$ctl00' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: An error has occurred because a control with id 'ctl00$cphContent$gvInvoiceslist$ctl07$ctl00' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
Amit ChoudharyPosted Feb 18, 2010, 2:00 AM
please copy the error message you are getting.. so that your problem get more clear.