Store GridView to session C#.Net [duplicate] - c#

I have a page for searching when I write my name for example in textbox it will search and display the results in a GridView. I'm using an EntityDataSource with a QueryExtender so I didn't write any code in C#.
The problem is: in the GridView I have a hyperlink when I click it, it will go to another page, ok fine then when I return to the previous page the GridView does not show the results of the search when I was left because of the postback (update panel) it show the whole data from EntityDataSource.
I think I have to use session but I don't know how I can do it, I mean how I can save the GridView in session and how I can retrieve it in page_load.

Related

Clear GridView without using the EmptyDataTemplate message

I have an ASP.Net page with a GridView control (id = GeneralGridView), that has an EmptyDataTemplate:
<EmptyDataTemplate>
<strong>No records found!</strong>
</EmptyDataTemplate>
When I first load the page, nothing is bound to the GridView so this message doesn't show.
I have a Clear method that currently does this:
GeneralGridView.DataSource = Nothing
GeneralGridView.Columns.Clear()
GeneralGridView.DataBind()
But using that technique will show the EmptyDataTemplate
Is there any way I can clear the results from a GridView without showing the Empty Template Message and without just reloading the entire page?
Well, you could remove the empty template - you don't need it. It not clear if you simply don't want that template ever showing, or in fact you want to clear the grid, and not show the empty template WHEN you decide to clear the grid?
However, if the user can say enter data, and hit search, then it is RATHER NICE to have the no data show.
but, if you whack your own custom clear button, then the no data will show - so I kind of get your point. You can do this:
GridView1.DataSource = null;
GridView1.EmptyDataTemplate = null;
GridView1.DataBind();
so, your clear button will clear the grid - and NOT show no data template.
You find that if you do a search, and re-bind, then you still get/see the "no data" template, and as noted this is often desired for a search criteria that returns no data, but a clear button should not show "no data".
thus above should work fine.

Obtaining Data From Repeater asp.net

I am an amateur as far as asp.net is concerned. What I'm trying to do is that I have a repeater control in my page that is set to show data upon selection of an item in a radio button list.
Upto this point its all good, next what I have to do is: I want a book now button for each repeater item which I can do as well.
But the question is: after user clicks book now how do I know which repeater item user has clicked? And how do I get the h_id(unique id of the table that repeater shows data of) of that item so that I can do further operations.
You could have a button or link in the repeater which an Eval("ID") as its commandargument and then use that value on postback - ala http://www.aspsnippets.com/Articles/ASPNet-Repeater-Get-Item-ItemIndex-CommandName-and-CommandArgument-on-Click-Events.aspx

Get the datasource of current tab in an advanced banded gridview

I have an advanced banded gridview inside a usercontrol which has different tab pages inside it.
I'm trying to find the specific datasource/datatable which is currently displaying.The following both return a table but it returns the same table irrespectively on which tab page I currently have selected.
((GridView) sender).DataSource;
((GridView) sender).DataController.ListSource;
The closest I could get was using a masterRowExpanded event and doing the following inside it:
((GridView) sender).GetRelationName(e.RowHandle,e.RelationIndex)
and this returned the name of the tab page I was currently on. Any ideas on how to retrieve the source would be greatly appreciated.
After struggling for a while I managed to get it, inside the masterRowExpanded event I used:
GridView gv = sender as GridView;
AdvBandedGridView abgv = (AdvBandedGridView)(gv.GetDetailView(e.RowHandle,RelationIndex));
Then the advanced banded gridview had the datasource I was looking for.

Non editable row in GridView

I am creating a web page using C# ASP.NET and Visual Studio 2008. I would like to create a dataentry form on my web page using GridView. Whenever a user may, he/she can edit the record on GridView (I have did this using edit, update, cancel option) but I would like to place another button in GridView named "Close" by which user can make that particular record "Non-editable". After clicking on close button on Gridview that record get locked and no body can edit that record in future.
Can anybody help me?
Maybe you can do that by adding a column to your table in your database. If the close button was clicked in your gridview, update the data in the database and make it closed so that it cannot be edit in your gridview.
Hope this gives you idea.

Transferring DropDownList values from one page to the next

I have 2 pages, both with 3 similar DropDownLists. The first DropDownList needs to be populated before selecting the second, and the second before the third (which then populates a gridview).
Usually, a user will view data on one page, click a button, and then view data on the next page (usually with the same DropDownList selections). Is there any way to have the dropdownlists pre-populated with their old selections?
You can pass values from one page to the other using the PreviousPage parameter that asp.net provides you. A small example:
You set the second page on the submit button as:
PostBackUrl="SecondPage.aspx"
On SecondPage.aspx you declare where you can get informations
<%# PreviousPageType VirtualPath="~/FirstPage.aspx" %>
and you get them by...
if (Page.PreviousPage != null)
{
if(Page.PreviousPage.IsCrossPagePostBack == true)
{
// and get the controls of the previous page as
var SomeVariable = PreviousPage.DropDownlListId.SelectedValue;
}
}
Some reference.
Cross-Page Posting in ASP.NET Web Pages
ASP.NET how to access public properties?
Cross-page postbacks and back again retaining data from source page
Cross-page posting. Is it a good pratice to use PreviousPage in Asp.net?
If you have the form where the button that the users click post to the second page, the second page can look for the values of the DDL and set them on page load.
There is a way:
pass selections to the second page either via Session or Query String
populate first dropdown
select appropriate item
repeat 2-3 for the rest of dropdowns
If you're looking for a magic solution that just "does that", I don't think this is possible.
p.s. You might rethink your design (if this is an option) and have the grid on the first page; bind the grid when user selects a value from the last dropdown (make sure you have AutoPostback set to True on your last dropdown in order to trigger the final postback)

Categories