473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1530
You can get it in the code as Request.QueryString["id"].

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

<asp:querystringparameter name="id" type="String" querystringfield="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**************@TK2MSFTNGP03.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:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:Ricambi_2ConnectionString %>"

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

</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

CellPadding="4" DataKeyNames="IDProdotto" DataSourceID="SqlDataSource1"

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

<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

<Columns>

<asp:BoundField DataField="IDProdotto" HeaderText="IDProdotto"

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

<asp:BoundField DataField="Codice" HeaderText="Codice"

SortExpression="Codice" />

<asp:HyperLinkField DataNavigateUrlFields="Codice"

DataNavigateUrlFormatString="defpost.aspx?id={0}"

DataTextField="Codice" NavigateUrl="defpost.aspx" />

<asp:BoundField DataField="Codice" />

<asp:BoundField DataField="Prodotto_I" HeaderText="Prodotto_I"

SortExpression="Prodotto_I" />
<asp:BoundField DataField="Nome_Pdf" HeaderText="Nome_Pdf"

SortExpression="Nome_Pdf" />

</Columns>

<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"
/>

<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"
/>

<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<EditRowStyle BackColor="#999999" />

<AlternatingRowStyle BackColor="White" ForeColor="#284775" />

</asp:GridView>

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

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

<asp:querystringparameter name="id" type="String" querystringfield="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**************@TK2MSFTNGP03.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
<SelectParameters>
<asp:querystringparameter name="id" type="String" querystringfield="id"
/>
</SelectParameters>
</asp:SqlDataSource>

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**************@TK2MSFTNGP02.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:SqlDataSource ID="SqlDataSource1" runat="server"

ConnectionString="<%$ ConnectionStrings:Ricambi_2ConnectionString %>"

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

</asp:SqlDataSource>

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

CellPadding="4" DataKeyNames="IDProdotto" DataSourceID="SqlDataSource1"

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

<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

<Columns>

<asp:BoundField DataField="IDProdotto" HeaderText="IDProdotto"

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

<asp:BoundField DataField="Codice" HeaderText="Codice"

SortExpression="Codice" />

<asp:HyperLinkField DataNavigateUrlFields="Codice"

DataNavigateUrlFormatString="defpost.aspx?id={0}"

DataTextField="Codice" NavigateUrl="defpost.aspx" />

<asp:BoundField DataField="Codice" />

<asp:BoundField DataField="Prodotto_I" HeaderText="Prodotto_I"

SortExpression="Prodotto_I" />
<asp:BoundField DataField="Nome_Pdf" HeaderText="Nome_Pdf"

SortExpression="Nome_Pdf" />

</Columns>

<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center"
/>

<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333"
/>

<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<EditRowStyle BackColor="#999999" />

<AlternatingRowStyle BackColor="White" ForeColor="#284775" />

</asp:GridView>

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

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

<asp:querystringparameter name="id" type="String" querystringfield="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**************@TK2MSFTNGP03.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 #4

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

Similar topics

3
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...
0
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...
0
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...
2
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...
2
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...
1
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...
1
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...
2
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...
0
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,...

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.