|
hi
i have gridview in my asp.net webform.
i bind my database to gridview like this:
SQL = "SELECT id,Fname,Lname FROM MEN";
dsView = new DataSet();
adp = new SqlDataAdapter(SQL, Conn);
adp.Fill(dsView, "MEN");
adp.Dispose();
GridView1.DataSource = dsView.Tables[0].DefaultView;
GridView1.DataBind();
and this i put in the gridview: `allowPaging = true`
its show the data in the grid, but if i press to page 2..3..
and i got this error:
The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
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: The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
thanks in advance
|
|
|
|
|
It's telling you exactly what the probelm is: you have not created the PageIndexChanging event and handled it which is what you need to do unless you use one of the built in data sources that will give you paging and sorting for free. In design view, click on the grid, and view the event properties. Double-Click on the appropriate row and the method will be created for you. Now handle the event.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Gali1978 wrote: The GridView 'GridView1' fired event PageIndexChanging which wasn't handled.
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.
Write a method for binding of Gridview
Private void BindGridView()
{
SQL = "SELECT id,Fname,Lname FROM MEN";
dsView = new DataSet();
adp = new SqlDataAdapter(SQL, Conn);
adp.Fill(dsView, "MEN");
adp.Dispose();
GridView1.DataSource = dsView.Tables[0].DefaultView;
GridView1.DataBind();
}
You Need Handle Gridview_pageIndexing event of GridView like this.
GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridView();
}
OR
After First Retrial of Data -- Put The DataSet into ViewState Or Session.(Here also Gridview1_PageIndexChanging event is Required. In this event bind the gridview with DataSet(i.e DataSet from ViewState or Session))
See This Link Gridview in ASP.NET 2.0[^]
I hope you issue will clear. Try this, Post here if you face any problem.
|
|
|
|
|
thanks for the help !
but I constantly see the same records, why ?
|
|
|
|
|
Gali1978 wrote: but I constantly see the same records, why ?
May be several reasons(Not exactly) .like Table contains duplicate rows (just check it once), Check Gridview Pager Settings (Page Size, Paging Modes).
If you post your modified code here, i will check it.
|
|
|
|
|
try this.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
}
protected void GridView1_PageIndexChanged(object sender, EventArgs e)
{
GridView1.DataBind();
}
suchita
|
|
|
|
|
thanks for the help, but still i see the same records
|
|
|
|
|
goldsoft wrote: but still i see the same records
Post your code here.
|
|
|
|
|
Hello!
Are there any open source ASP.NET MVC GUIs for users/roles management?
Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.
|
|
|
|
|
|
Thanks for the link. Yeah, I've already found it. What I want to find is something more complicated, like MyWSAT[^] – but for MVC
Die Energie der Welt ist konstant. Die Entropie der Welt strebt einem Maximum zu.
|
|
|
|
|
I have a checkbox in my page which is autopostback true. If the user clicks on the checkbox,
I want to display a confirmation text box in javascript, and if the user clicks on Ok,
then only the postback should occur, otherwise not. Even though the js is working and
confirmation box displays, no postback is happening.
Below is my code:
Javascript code:
function ReportConfirmation() {
if (confirm("Proceeding with Output File Generation ? ")) {
return true;
}
else {
return false;
}
}
<asp:CheckBox runat="server" ID="chkGenerateRpt" AutoPostBack="true" OnCheckedChanged="chkGenerateRpt_CheckedChanged" Text="Generate Reports"/>
Code-Behind in PageLoad (outside the IsPostBack):
chkGenerateRpt.Attributes.Add("OnClick", "javascript:return ReportConfirmation(); ");
protected void chkGenerateRpt_CheckedChanged(object sender, EventArgs e)
{
if (chkGenerateRpt.Checked)
{
}
}
If i remove return from the pageload code above, the page will work irrespetive of
whether the user clicks on cancel or Ok button in confirmation box? Could anybody
please help in finding out the error?
Thanks in advance
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
I checked the page source and found that: if you enable AutoPostBack for a check box, an onclick handler is automatically attached to the page. Now when you add another onclick event to the page both of them are concatenated and looks like this -
<input id="chkGenerateRpt" type="checkbox" name="chkGenerateRpt" onclick="javascript:return ReportConfirmation(); ;setTimeout('__doPostBack(\'chkGenerateRpt\',\'\')', 0)" /><label for="chkGenerateRpt">Generate Reports</label>
See the bold part. Thus it is not working.
Now how we can overcome this problem:
This thread describes the possible solutions -
http://www.dotnetmonster.com/Uwe/Forum.aspx/asp-net-web-controls/4449/Checkbox-AutoPostBack-JavaScript[^]
I will paste the solution here as well -
1. Manualy create a new checkBox class which derived from the asp.net's
CheckBox control and override the render method so as to insert our own
script before the build in "AutoPostBack" script (__doPostBack)
2. Use the InputCheckBox control in the System.Web.UI.HtmlControls
namespace and we can add a serverchange event for it and also handler its
clientside "onclick" script event. But we need to manually post back the
page when user click it at clientside, for example:
<input type="checkbox" id="chkClient" runat="server" value="..."
name="chkClient" onclick="alert('hello');document.forms[0].submit();"
onserverchange="chkServer_CheckedChanged">
in page's codebehind we have :
protected void chkServer_CheckedChanged(object sender, System.EventArgs e)
{
Response.Write("<br>CheckChanged at: " + DateTime.UtcNow.ToString());
}
I hope this clears your doubt and solves your issue!
Cheers!
Ankur
..Go Green..
|
|
|
|
|
Thank you Ankur. I think the second one is the best option. Thanks a lot !!!
Success is the good fortune that comes from aspiration, desperation, perspiration and inspiration.
|
|
|
|
|
I am glad that it helped you.
Cheers!
Ankur
..Go Green..
|
|
|
|
|
sir i need the documentation for the project "SYSTEM INFORMATION DESKTOP TOOL" its urgent sir and it is related to my project so plz send the documentation to my gmail id "inturi143@gmail.com"
its urgent sir
thanking you
|
|
|
|
|
If you need some help on an related article here on CP SYSInfo: System info desktop tool[^] it would be appropriate to leave a message on the board of said article. You can download and study the code and whatever there is, but if you need further assistance you need to contact the author instead of posting it here.
Cheers!
|
|
|
|
|
Hi,
I am creating a new datalist custom control, basicly why I need this solution is that. I will use it in pretty same way with same columns (maybe column names that return is different).
The question is that I am unable to add itemtemplate to this server control... Could you please assist me with the codes and the event name that adds this control.
Thanks in advance
|
|
|
|
|
|
Hi,
thanks for the answer, but what I need is not about the common datalist control, I am creating my own datalist control via web server controls. So I am overwriting some of the common datalist controls' events. I need my datalist control to come with an itemtemplate by default. This itemtemplate will require some fields that will be provided by properties.
There are two events while creating your own control
1. rendercontents
2. createchildcontrols
I was unable to addd itemtemplate by these 2 events.. How could I manage this, I do not know at the moment.
I hope I made myself clear now.
|
|
|
|
|
In addition to thatraja list, see also this[^]
|
|
|
|
|
Hi,
thanks for the answer, but what I need is not about the common datalist control, I am creating my own datalist control via web server controls. So I am overwriting some of the common datalist controls' events. I need my datalist control to come with an itemtemplate by default. This itemtemplate will require some fields that will be provided by properties.
There are two events while creating your own control
1. rendercontents
2. createchildcontrols
I was unable to addd itemtemplate by these 2 events.. How could I manage this, I do not know at the moment.
I hope I made myself clear now.
|
|
|
|
|
Hi,
I need to prevent multiple users updating same record same time and same table ,
i tried with Sq l-transactions ,
every user data updating properly but last user data will be the current data ,
here i need to show alert message for second user onwards.
Please suggest me better way to do this.
Regards,
Vishnu.
|
|
|
|
|
The accepted way to do this is to hold some form of version information on the table (be it an update tickcount, or incrementing number). Retrieve this with your record, and pass it back in when you attempt to update the record. If the version doesn't match on the update, it means that somebody else has updated the record while you were editing it. At this point, you can inform the user that the record has been updated by somebody else.
|
|
|
|
|