Link to a New .aspx Page from Selected Database Entry by User - asp.net

I am working on a website using C# in ASP.NET and have a page that contains a grid-view which displays the contents of one of the tables in my database. The fields are generic like Name, Description, Rating, ect. My question is how do you make it so that when one of the entries is clicked, it links to a new .aspx page that has all its information displayed in a nice format? An example of what I am talking about can be found at http://www.imdb.com/chart/top?ref_=nv_ch_250_4.
From my research I have found very little in the way of an answer, probably due to my inability to ask this question correctly. I assume your not suppose to physically create a new page for every new entry, because that could get crazy if you have lots of database entries coming in. Should there be one page created that auto-populates the required fields based on the specific values passed from the database entry selected, or when a user inserts a new entry into my database should I also create a new .aspx page? This question has had me stuck for quite some time, so I would appreciate any direction you can provide!

Create a simple hyperlink for all rows of the grid, the url of the hyperlink should contain a reference to that item like a ID or name. When the link is clicked you are passing the id to the second page in querystring. In the second page read the id(request.querystring) and display details accordingly.
>
Making the hyperlink : this is one way to do it. Add a itemtemplate column in the grid.
<Columns>
<asp:TemplateField >
<ItemTemplate>
View Details
</ItemTemplate>
</asp:TemplateField>
</Columns>

Brian,
You would have ONLY ONE new page that handles all of your entries in that table. You need to create this page such that it reads a query string from the URL, say with an id that corresponds to one of the records in your grid. In your grid, construct a link per record with an appropriate id that, when your newly created page receives it via URL, it can look up that one record in the database and populate the new page.
For example, a link in one of the rows of your grid could look like this:
/NewPage.aspx?id=123
Then, in the new page you created (NewPage.aspx) get the id that was passed and populate the page accordingly. For example:
string id = Request.QueryString["id"];

Related

How to show the related data of a gridview in new window/

I am doing a project in which i am getting data from a database and displaying in asp:gridview. i want to show a hyperlink column in which i want to show a proper named hyperlink for example "View" and when the user click on "View" the data from the DataTextField property is displayed in detail on another page let say "WebForm1.aspx".i have searched on net and have studied on msdn bt couldnt get. detailed help will appreciated .. piece of code as example will be helpful . thanks in advance.
Example:
data in the database table
NewsID NewsTitle NewsArticle (NewArticle field contains large amount of data)
i want to show a proper link named("view"). when user click on the view ,NewsArticle of the related record should be displayed in a new separate webpage.
One way to do this is for the hyperlink/url contained in each row of the grid view to contain the id of the record you want to view the detail, i.e.
View
then in the page_load event of the webform1.aspx you retrieve that record from the database and dispaly it on the page.
There are lots of ways to skin this cat, this is a relatively simple one. The code below is what you might use to generated the html above:
<asp:HyperLinkField HeaderText="Name" DataTextField="Id" DataNavigateUrlFields="DetailId" DataNavigateUrlFormatString="WebForm1.aspx?ID={0}">
</asp:HyperLinkField>
If you are familiar with Jquery you can user Dialogs
http://jqueryui.com/dialog/

Binding gridview with xml file at client side

hi i have two xml file and i want to bind grid view eith this xml file on client side. i try to describe the complete senerio. in my .aspx page i have a drop down list which has number of department. when the user select the department the data i want the data according to department comes on the grid view from first xml file, in this gridview the rows are field with various tests and the row also have a checkboxes ,when user click on that checkbox the datafrom yhe second xml file will come and the second grid view is bind with that data. i want all that on client side. how is that possible, please help me and thanks in advance for help
I would suggest you to either use jqgrid/html table and use this article to read xml using javascript or if you wants to use gridview only and don't wants to show post back to the user then use updatepannel with gridview will help you out.

Getting form field names on Submit when form is user control

I am slowly, piece by piece learning what I am doing with ASP.NET
I've created the beginnings of my new web application, but I am often coming up against the issue that ASP.NET renames elements IDs or in the case of form fields, their names.
I have a form which is basically a sales system. It is essentially made up of two User Controls, one is a form for Customer Details (name, address etc) and the second is a form for the customer's purchases, it consists of a number lines dynamically created by Javascript created as you list the items the customer is purchasing.
Both these sections are User Controls because they are to be used for other areas of the system where this data will need to be recalled/re-entered.
When the USer Control is loaded, the field which contains the Customers' Name is renamed "m$mainContent$customerForm$name" I understand where this comes from, "m" is the ID of my Master Page, "mainContent" is the main Content Placeholder and "customerForm" is the name of the User Control.
In fact, in my case, this will always remain the same on all forms, so it is relative easy to overcome... but... suppose it wasn't
I can see there are ways I could deal with this with Javascript, but the form doesn't need an AJAX submit, a normal Post will do fine for this, so when I open up the recieving page I want to call Request.Form("name")% to save the customer's name into the database, but of course I really need Request.Form("m$mainContent$customerForm$name")%
How would I dynamically extract those prefixes from the posting form to ensure that if I rename anything or use it in a different scenario, the problem will not break it?
I am using .NET 2.0, so can't use Static Client.
This is really old but let's see if it's useful for you.
Getting this example I managed to get the value from a given field name without prefix.
I'm sure it is not the best solution, but it was useful for me. Let's say you want to recover the value of a field named "hfIdAviso", that comes in the POST as "ctl00$body$hfIdAviso":
var value = Request.Form.Cast<string>()
.Where(key => key.EndsWith("hfIdAviso"))
.ToDictionary(key => key, key => Request.Form[key])
.Values.FirstOrDefault();
That will return the value for that field.
Hope it helps.
If you include runat="server" in the declaration of your user control in the ASPX page, then you can access this control by just using the ID value of the control.
For example
In the ASPX:
<uc:MyUserControl ID="mycontrol1" runat="server" />
In the code behind (in C# syntax):
object foobar = mycontrol1.SelectedValue;
suppose you have a form inside user control that has a TextBox field with ID="txtfname".You have registered your user control in page1 and you want to POST form data to page2 :
in page1 you have user control:
<My:WebUserControl1 ID="myuc" runat="server" />
in page2 codebehind , you can get the value of user control form field (txtfname) this way :
string firstName = Request.Form["myuc$txtfname"];

ASP.Net, how to put hyperlinks in datagrids.

Hi i have a datagrid I've put in on a aspx web form in visual studio 2010, I'm new to this so I've been following the ms tutorials.
One of the columns on my data grid contains a lot of information, is there a way i can add a "+more" option in the cell next to the entry that shows only the first few characters of that cell, but once clicked opens all the information on that particular entry but onto a new aspx form?
Thanks for any help!!
There are basically three different ways...
Structure your data object/query so that it returns a key and and abbreviation (i.e, first name, last name, id, bio) and use a template that turns id into a link.
Use the onrowbound event to manipulate the controls on the row, so that you have a href to your details page.
Use css to show the additional info on a hover/mouse over (I like this, but it doesn't play well with mobile devices, which don't have either event).
EDIT: Methods 1&3 would be done on your aspx page, method 2 would be done in the codebehind for your page. Method 1 is really dependent upon your being able to control the data object/ query results. If you are calling a stored proc that someone else controls, it may be very difficult to make it work.

Telerik RadGrid Manipulating data from data source before databinding an item

I am working with a Telerik Radgrid on an aspx page, which basically has to bind to a datatable, which gets populated by data returned from a web service. I need to be able to fill out some of the columns in the RADGRID based on the data returned by the web service.
For example, I need to be able to build the Hyperlink column based on the parts data returned by the web service. I need a way to access the datasource before the grid item gets populated and direct execution to a routine which builds the URL for the parts on a website.
Can anybody please suggest an efficient way to do this?
I highly appreciate any help/suggestions.
Thanks
Karthik
(Moving my comment to an answer, because I'm thinking this will work out for you.)
You could always cheat and bind it to the grid, allowing you to access the data, but then hide the columns so the users could never get the data.
Let me know how it works out.
EDIT:
My select statement is "select top 5 ProductName from products"
I then created a hyperlink column and assigned the properties under the data tab as such.
When run, it makes the data clickable and when clicked, it navigates to the url seen in the SS.
That what you need?

Resources