How to programmatically browse through the pages of a data-bound DetailsView?
I am using this code:
protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
{
DetailsView1.PageIndex = e.NewPageIndex;
}
The page is changing. But the problem is, the next record item is not showing up. The old item is still visible on the new page.
You have to re-bind your details view.
Related
I have a bunch of GridView on one page, and each have their own coordinating SqlDataSource.
They all load their coordinating data when initializing the page (on the page load). I want to Load the data for specific SqlDataSource(s) on the page when the user clicks a button, so that it is not trying to load ALL the data for all the different grids all at the same time when the page initially loads.
Note: I need to also have Paging working, and anything I have tried so far has broken the paging functionality.
Looking to tell the SqlDataSource what data to bind to it after the user clicks a button, and then have the specific GridView Bind that data to it and have the Paging functionality work with the data it was told to load.
Environment: C#, WebForms, ASP.NET, .NET 3.5, Controls SqlDataSource / GridView
From what I can tell it correctly binds the data, but the 'gridview' control keeps disappearing when I click one of the pages at the bottom for the paging.
Note: If I click the button again, it will show the correct page and the correct data for the page.
protected void btn_LoadData2_Click(object sender, EventArgs e) { Gridview2.DataSourceID = "DataSource2"; Gridview2.SelectCommand = "SELECT * FROM dbo.DataNeeded"; Gridview2.DataBind(); Gridview2.DataBind(); }
Add a Selecting event to each of your data sources. Then in the code behind check if IsPostBack and if IsPostBack is false then cancel the operation.
protected void MyDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
if (!IsPostBack)
e.Cancel = true;
}
I have one asp.net page with two gridview using updatepanel.when i click the submit button data inserting in db and update the gridview. i'm handling duplicate insertion of same data when refresh the page. but the problem is when i refreshing the page previous data in the gridview showing not present data. again if i'm clicking the menu its reloading and showing actual data.i'm handling button click but i don't know how to handle this gridview problem when i refresh the page. if anybody pass through same problem please show some light on this or please give some suggession.
I would try:
gridviewObj.datasource = null
gridviewobj.datasource.databind();
... hope this helps
you could do this
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
//here you bind again the datagrid
}
}
Use if(IsPosback) in Page_Load event
then
UpdatePanel.Update();
I have this button event:
protected void AddDetails_Click(object sender, EventArgs e)
{
DataSetTableAdapters.SelectFriendsTableAdapter sft = new DataSetTableAdapters.SelectFriendsTableAdapter();
try
{
sft.AddFriend(current, newFriend, false);
}
catch
{
error.Text = "Something happened. Bummer!";
}
}
in the try section, I'm adding entries in the Database. In the page there are Labels / Textboxes with the corresponding values.
Everything works fine. However, I need to refresh the page in order to see the changes after I click on this submit button.
I have added if(!IsPostBack) at the beginning of the PageLoad code, but I still need to visit another page / come back to see the changes.
Any ideas?
Thanks.
Thank you for your replies. I'm using a ListView:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSetTableAdapters.SelectFriendsTableAdapter sdt = new DataSetTableAdapters.SelectFriendsTableAdapter();
DataTable tab = sdt.SelectFriends();
ListView1.DataSource = tab;
ListView1.DataBind();
}
}
, so the ListView content should get updated.
If you don't want to refresh the page and you're using asp.net webforms you can use an UpdatePanel and place all your controls inside of it, etc... That will keep the changes made in the form / display when you submit the info. I'm assuming the form is on submitting the changed/new data as you didn't specifically state how the data was being updated/changed.
If you don't want to use an update panel, then when the page is posting back you will have to set the values for the UI controls that you want to update with the values from the 'newFriend' object (I'm assuming that has the changed values).
Found it!
The solution for this issue is to add this code at the end of your submit button click event:
Server.Transfer("currentpage.aspx");
I have a gridview to which I am allocating a data source and binding it on Button Click in Code behind.
Code:
protected void Button2_Click(object sender, EventArgs e)
{
GridView1.DataSource=List;
GridView1.DataBind();
}
asp.net
It was working fine until I decided to put this grid view inside a tab panel. As soon as I put the gridview inside the tab it is not able to access the gridview.
I tried using FindControl to find GridView3 but its not working.
Can somebody suggest me a work around?
Thanks
try looping over all the containers in tab-panel:
foreach(var c in tab_panel.Controls)
{
if(c is your control)
return c;
if(c is a container)
loop through all controls in c;//recursion
}
Have you tried:TabPanel.Children?
I have an asp.net CheckBox, now I want to reload page after check or uncheck and use CheckBox.Checked information to choose sql query for gridview. I have put code like this in Page_Load method:
if (CheckBox1.Checked)
{
query = "select ...";
}
But nothing happen. I set AutoPostBack also. Tried to use event. Don;t know how this system works:/
EDIT:
Checkbox works ok, but the problem is in something different. After I click checkbox, in Page_Load method I will use my query to setup SqlDataSource. Looks like page is reloaded, but gridview is not refreshed. When i click on gridview's column mame (to sort this column), gridview is refreshed by new sql query. So i need to think how to refresh grid view after click check box.
It seems that you are not using IsPostBack property on page load event. If you not use this your CheckBox will be reset on every page load
Try this way
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Here do your stuff.
}
}