Postback to display data in a gridview

Z

Zaur Bahramov

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
 
E

Eliyahu Goldin

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
 
Z

Zaur Bahramov

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 said:
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 said:
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
 
E

Eliyahu Goldin

<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 said:
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 said:
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,823
Latest member
Nadia88

Latest Threads

Top