473,804 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Postback to display data in a gridview

Hi!

I'm developing a web application where the first page shows table from SQL
Server and has some hyperlinks in one collumn. The collumn has productID so
when clicked the page is passed as defpost.aspx?id ={0}

When user clicks on a hyperlink it is redirected to defpost.aspx page where
basing on the value of ID the data grid needs to display another table after
querying a SQL Server passing the parameter (which is equal to "id").

The first part is clear and is ready, I'm having a difficulty creating a
defpost.aspx page. How do I grab the ID and pass it to sql query on
defpost.aspx?

Thank you!
Zaur
Jul 21 '08 #1
3 1559
You can get it in the code as Request.QuerySt ring["id"].

If you are using SqlDataSource control, you can get away without writting
any code if you use a QueryStringPara meter:

<asp:querystrin gparameter name="id" type="String" querystringfiel d="id" />
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Zaur Bahramov" <zb********@msn .comwrote in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
Hi!

I'm developing a web application where the first page shows table from SQL
Server and has some hyperlinks in one collumn. The collumn has productID
so when clicked the page is passed as defpost.aspx?id ={0}

When user clicks on a hyperlink it is redirected to defpost.aspx page
where basing on the value of ID the data grid needs to display another
table after querying a SQL Server passing the parameter (which is equal to
"id").

The first part is clear and is ready, I'm having a difficulty creating a
defpost.aspx page. How do I grab the ID and pass it to sql query on
defpost.aspx?

Thank you!
Zaur


Jul 21 '08 #2
Thank you very much!

Where should I insert this line in my code? (Sorry for this question, i'm
not yet proficient enough in ASP.NET)

<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"

ConnectionStrin g="<%$ ConnectionStrin gs:Ricambi_2Con nectionString %>"

SelectCommand=" SELECT [IDProdotto], [Codice], [Prodotto_I], [Nome_Pdf] FROM
[Prodotti]">

</asp:SqlDataSour ce>

<asp:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"

CellPadding="4" DataKeyNames="I DProdotto" DataSourceID="S qlDataSource1"

Font-Names="Verdana" Font-Size="X-Small" ForeColor="#333 333"
GridLines="None ">

<FooterStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e" />

<RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" />

<Columns>

<asp:BoundFie ld DataField="IDPr odotto" HeaderText="IDP rodotto"

InsertVisible=" False" ReadOnly="True" SortExpression= "IDProdotto " />

<asp:BoundFie ld DataField="Codi ce" HeaderText="Cod ice"

SortExpression= "Codice" />

<asp:HyperLinkF ield DataNavigateUrl Fields="Codice"

DataNavigateUrl FormatString="d efpost.aspx?id= {0}"

DataTextField=" Codice" NavigateUrl="de fpost.aspx" />

<asp:BoundFie ld DataField="Codi ce" />

<asp:BoundFie ld DataField="Prod otto_I" HeaderText="Pro dotto_I"

SortExpression= "Prodotto_I " />
<asp:BoundFie ld DataField="Nome _Pdf" HeaderText="Nom e_Pdf"

SortExpression= "Nome_Pdf" />

</Columns>

<PagerStyle BackColor="#284 775" ForeColor="Whit e" HorizontalAlign ="Center"
/>

<SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True" ForeColor="#333 333"
/>

<HeaderStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e" />

<EditRowStyle BackColor="#999 999" />

<AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />

</asp:GridView>

"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgha scritto nel
messaggio news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
You can get it in the code as Request.QuerySt ring["id"].

If you are using SqlDataSource control, you can get away without writting
any code if you use a QueryStringPara meter:

<asp:querystrin gparameter name="id" type="String" querystringfiel d="id" />
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Zaur Bahramov" <zb********@msn .comwrote in message
news:e5******** ******@TK2MSFTN GP03.phx.gbl...
>Hi!

I'm developing a web application where the first page shows table from
SQL Server and has some hyperlinks in one collumn. The collumn has
productID so when clicked the page is passed as defpost.aspx?id ={0}

When user clicks on a hyperlink it is redirected to defpost.aspx page
where basing on the value of ID the data grid needs to display another
table after querying a SQL Server passing the parameter (which is equal
to "id").

The first part is clear and is ready, I'm having a difficulty creating a
defpost.aspx page. How do I grab the ID and pass it to sql query on
defpost.aspx ?

Thank you!
Zaur



Jul 21 '08 #3
<SelectParamete rs>
<asp:querystrin gparameter name="id" type="String" querystringfiel d="id"
/>
</SelectParameter s>
</asp:SqlDataSour ce>

Specify the correct type and make you SelectCommand like

"select ..... where [IDProdotto] = @id
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Zaur Bahramov" <zb********@msn .comwrote in message
news:Oa******** ******@TK2MSFTN GP02.phx.gbl...
Thank you very much!

Where should I insert this line in my code? (Sorry for this question, i'm
not yet proficient enough in ASP.NET)

<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server"

ConnectionStrin g="<%$ ConnectionStrin gs:Ricambi_2Con nectionString %>"

SelectCommand=" SELECT [IDProdotto], [Codice], [Prodotto_I], [Nome_Pdf]
FROM [Prodotti]">

</asp:SqlDataSour ce>

<asp:GridView ID="GridView1" runat="server" AutoGenerateCol umns="False"

CellPadding="4" DataKeyNames="I DProdotto" DataSourceID="S qlDataSource1"

Font-Names="Verdana" Font-Size="X-Small" ForeColor="#333 333"
GridLines="None ">

<FooterStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e" />

<RowStyle BackColor="#F7F 6F3" ForeColor="#333 333" />

<Columns>

<asp:BoundFie ld DataField="IDPr odotto" HeaderText="IDP rodotto"

InsertVisible=" False" ReadOnly="True" SortExpression= "IDProdotto " />

<asp:BoundFie ld DataField="Codi ce" HeaderText="Cod ice"

SortExpression= "Codice" />

<asp:HyperLinkF ield DataNavigateUrl Fields="Codice"

DataNavigateUrl FormatString="d efpost.aspx?id= {0}"

DataTextField=" Codice" NavigateUrl="de fpost.aspx" />

<asp:BoundFie ld DataField="Codi ce" />

<asp:BoundFie ld DataField="Prod otto_I" HeaderText="Pro dotto_I"

SortExpression= "Prodotto_I " />
<asp:BoundFie ld DataField="Nome _Pdf" HeaderText="Nom e_Pdf"

SortExpression= "Nome_Pdf" />

</Columns>

<PagerStyle BackColor="#284 775" ForeColor="Whit e" HorizontalAlign ="Center"
/>

<SelectedRowSty le BackColor="#E2D ED6" Font-Bold="True" ForeColor="#333 333"
/>

<HeaderStyle BackColor="#5D7 B9D" Font-Bold="True" ForeColor="Whit e" />

<EditRowStyle BackColor="#999 999" />

<AlternatingRow Style BackColor="Whit e" ForeColor="#284 775" />

</asp:GridView>

"Eliyahu Goldin" <RE************ **************@ mMvVpPsS.orgha scritto
nel messaggio news:%2******** ********@TK2MSF TNGP03.phx.gbl. ..
>You can get it in the code as Request.QuerySt ring["id"].

If you are using SqlDataSource control, you can get away without writting
any code if you use a QueryStringPara meter:

<asp:querystri ngparameter name="id" type="String" querystringfiel d="id"
/>
--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Zaur Bahramov" <zb********@msn .comwrote in message
news:e5******* *******@TK2MSFT NGP03.phx.gbl.. .
>>Hi!

I'm developing a web application where the first page shows table from
SQL Server and has some hyperlinks in one collumn. The collumn has
productID so when clicked the page is passed as defpost.aspx?id ={0}

When user clicks on a hyperlink it is redirected to defpost.aspx page
where basing on the value of ID the data grid needs to display another
table after querying a SQL Server passing the parameter (which is equal
to "id").

The first part is clear and is ready, I'm having a difficulty creating a
defpost.asp x page. How do I grab the ID and pass it to sql query on
defpost.asp x?

Thank you!
Zaur




Jul 21 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11777
by: Simon Strandgaard | last post by:
Hi group, my setup: I have a GridView that extracts data from my table (a SqlDataSource). For each row, I have an 'edit' button and a 'delete' button. The 'edit' button opens a popup, through which one can insert and edit the table. The 'delete' button deletes the row.
0
2119
by: Managed Code | last post by:
Hello All, Here is my issue and thanks in advance for any assistance. I have a base page with a dropdownlist that fires an event with the selected index. The content page catches the event and sets a connection string to the database. The content page has a simple gridview that should show records from the selected database. Initial content page displays data from correct place. first change of dropdownlist correctly updates content...
0
2226
by: John Smith | last post by:
I still have not gotten this damn thing figured out and I'm asking for help one last time before I give up on it. I have a user control that contains a paged gridview control. The master page contains a menu control What I want to happen is that, whenever a menu item is selected, the appropriate user control will load. Simple enough? Well, not for me. I finally got the gridview paging and postback issue resolved thanks to...
2
17065
by: =?Utf-8?B?dmFuZGls?= | last post by:
I have a web app that I have been working on for the last couple of weeks trying to solve this problem. One page contains a GridView with four base columns, and an unknown number of columns to be added depending on the data source chosen. I create some TemplateColumns based on the data returned for the selection, and add them into the GridView using the following code: DataSet dsTraits = ssql_common.selectRubricTraits(sConnectionString,...
2
13203
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
1
11240
by: =?Utf-8?B?V2VzbGV5IERhdmlzLCBHZW5lcmFsIER5bmFtaWNz | last post by:
I'm moving from years with the datagrid to a new project, .net 2.0, using GridView controls. Per past practice, it is often a lot easier to inject controls (or special formatting) in RowDataBound (formerly ItemDataBound) than to mess with complicated templates, especially for things that are consistent across grids or columns. GridView is dumping all the nice stuff put there during a RowDataBound event. Ex: those "!" icons in outlook or...
1
9191
by: gabe | last post by:
How do you call a client side javascript callback method after an update panel has posted back to the server? I have two update panels (A + B) with a gridview in each panel. GridView B has a Trigger to listen when GridView A posts back from a Select button. This works fine. I can get the Postback from GridView B and I am able to update formatting of GridView B in it's PreRender Event.
2
9143
by: wildman | last post by:
RE: Gridview textbox has data check without postback.. javascript? I have a gridview with a textbox. I can set the textbox to autopostback and check for a value in a prerender event to decide if I should make a button on the grid row visible. However, the problem with autopostback on a textbox is the postback occurrs when you select another control or click away ( I guess). This is very awkward when the control selected is dropdown as...
0
1700
by: db007 | last post by:
I have a problem at the moment with a web project. I have two Panels within an UpdatePanel on an aspx page (using Masterpages). I'm using ASP.Net 2.0 with an AJAX enabled website. The two Panels represent a Master-Detail type relationship. I want a user to click a LinkButton in the first Panel and then for the 2nd Panel to be displayed with the detail. However, I need to set some text properties of textboxes programmatically when the...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.