GridView not visible in ContentPlaceHolder on content page - asp.net

I am trying to create a page that uses a MasterPage to organize content. On my content page, I have created a text search, which will filter a GridView presentation of data.
When I use the databinding in a non-master page setup, it works perfectly. But, as soon as I drop the controls into a contentplaceholder on my page, it no longer displays any results.
Any suggestions would be greatly appreciated.

try these
debug your page with breakpoints and be sure your gridview datasource is not null
make sure you have registerd the controls in master page
Sometimes it is due to css. also check css of content page
try to make controls on content page not just copy and paste them from another page
To fatch the values from previous page store values in session and on second page
DataSet ds = (DataSet)(Session["id"]);
Gridview1.DataSource = ds;
Gridview1.DataBind();

Related

Navigate to a certain page of a GridView from an other aspx page

I have a website with 2 pages, Master.aspx and Detail.aspx.
In Master.aspx there is a Gridview and when I click on a certain row it will redirect to Detail.aspx.
The Gridview inside Master.aspx implements "pager size", so when the user is inside Detail.aspx, I want them to be able to return to Master.aspx, precisely in the same page Gridview. To solve this problem I'm using the following JavaScript:
history.go(-n)
This allows the user to return to the correct Gridview page, however, it doesn't update the information inside the Gridview (naturally when the user makes changes in Detail.aspx).
How can I update the information inside the Gridview appropriately?
Moreover, I noticed that when I click the page buttons of the Gridview they use a __doPostBack() function:
<a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$GridView1','Page$3')"
style="color:White;">3</a>
Is it possible to use the __doPostBack function from Detail.aspx, to redirect to a specific page of the Gridview in Master.aspx?
When redirecting back to Master.aspx from Default.aspx you can have it go to the correct page index by passing the page index number through the url
Response.Redirect("Detail.aspx?id=" + gridview1.PageIndex.ToString()).
On Master.aspx you would then have to set the content of gridview1 then do
gridview1.DataBind();
gridview1.PageIndex = Request.QueryString("id")

Dynamically generated content in a PlaceHolder inside of a FormView?

Reaching out for some help here, as this has me stumped. Long story short, I've got a dynamic Table that is built from Functions, displayed in a Placeholder inside a FormView.
I have a 'save' button inside the EditItemTemplate of the FormView, CommandName="Save" - I have a Select Case (using VB here) and (almost) everything is working as expected.
However, when I pull my PlaceHolder in Code Behind, I'm showing no controls in the PlaceHolder.
Here's a brief rundown:
FormView ItemTemplate has a View_PlaceHolder that shows data from dynamically generated table correctly.
FormView EditItemTemplate has an Edit_PlaceHolder that loads the same Data from dynamically generated table into TextBox (works fine, same data is shown as expected)
When I click Save, my current code is:
Dim Edit_PlaceHolder as PlaceHolder = FormView1.FindControl("Edit_FV_PlaceHolder")
Dim EditTable as Table = Edit_PlaceHolder.FindControl("Edit_Plan_Holder")
Edit_PlaceHolder is not nothing, but has 0 controls in Controls.Count
Oh, one more bit of information - my Table is built and added to the PlaceHolder in the FormView.DataBound event.
What am I doing wrong?
You must repopulate and add the dynamically added table on PostBacks too, not just on the initial load. Check out the answer to this question for more detail.
Ok, so here's what was happening:
1) As NoAlias stated, need to keep the ID's. I used Page_Load to set a ViewState variable if I was in 'view' or 'edit' mode.
2) I used a separate BuildViewTable() method and BuildEditTable() method, and inside those called my separate class and constructed the table.
3) It's all working now :) Thanks, NoAlias!

Pass datatable to different page to be diaplyed in gridview

I have an aspx page with a gridview control. The code-behind for this page fills a datatable and then displays the datatable in the gridview. I then need to pass the datatable to a separate aspx page and display it again in a gridview on THAT page. I'm not sure how to go about this.
On the second page, in the code-behind, I'll have a simple function that receives a datatable and displays it in a gridview, but what is the best way to do what I'm trying to do? I need the gridview to display on the original page, but also display on the new page.
So... somehow display the gridview on page1, then pop open the new page and pass the datatable to my function? At a loss here.
You can try using Sessions, once you display the GridView for the first time, just save the DataTable it loaded into a Session, something like Session["griddata"] = myDataTable. Then in the other page just pull it out of the Session likeDataTable myDataTable = (DataTable)Session["griddata"]; then bind it to the grid.

How to rebind datagrid in asp.net 1.1 without postback?

I need to have datagrid(3 columns) to which the values will be added using 3 textboxes and a button(Add) on the same page. If click on Add button the value should append to datagrid without page refresh/reload?
Please guide me with your approaches to this problem? I ran out of search.
Have you considered using Ajax on the client-side? I presume that clicking the "Add" button is also supposed to update something on the back-end, which means you must do a round-trip of some kind. Either via a postback, but since you don't want this, then the only other option is Ajax whereby you'll make a separate asynchronous post to the back-end that will not cause a page refresh, and on the client script, inject the correct elements to "update" the grid on-screen. You could get that working as a prototype and then use knockout to simplfy the process.
1) I have used iframe in my default aspx page.
2) Created a new aspx page "datagrid.aspx" and had my datagrid as the only control in that page and set the src attribute of iframe to "datagrid.aspx"
3) Datatable to be rendered in datagrid.aspx is stored in the session variable in page load of default.aspx.
4) In the pageload of datagrid.aspx datatable is retrieved and binded to the datagrid.
5) When an item to be added/updated/removed are sent through querystring parameters from default.aspx using onclick event (JS) of a html button by setting the iframe source attribute.
Hope this answer helps.
If its not clear, Please comment.

Collapsible panel inside GridView

I'm developing an ASP.NET 3.5 web application using C# with AjaxToolkKit. I have a following question.
How can I put a collapsible panel inside GridView to make a master and detail list that expands to display the detail panel when view link in a row is clicked? This is something similar to the download list in MSDN page.
Thanks
Implement jQuery on the page. Have a look at the ajax methods, specifically in your case the load method. Show the master record on the page, along with a hidden div (you could inject it, but hey lets keep this simple ;). Bind the load to the click event of the master record displayed, and then use slideDown to show the hidden div on the page.
ie A very simply example of the load method, loading the html result from ajax/test.html into the element that is selected by 'result'
$('#result').load('ajax/test.html');

Resources