Postback to display data in a gridview

Discussion in 'ASP .Net' started by Zaur Bahramov, Jul 21, 2008.

  1. 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
     
    Zaur Bahramov, Jul 21, 2008
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Eliyahu Goldin, Jul 21, 2008
    #2
    1. Advertising

  3. 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" <> ha scritto nel
    messaggio news:%...
    > 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" <> wrote in message
    > news:...
    >> 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
    >>
    >>

    >
    >
     
    Zaur Bahramov, Jul 21, 2008
    #3
  4. <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" <> wrote in message
    news:...
    > 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" <> ha scritto
    > nel messaggio news:%...
    >> 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" <> wrote in message
    >> news:...
    >>> 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
    >>>
    >>>

    >>
    >>

    >
    >
     
    Eliyahu Goldin, Jul 21, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    18,022
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  2. =?Utf-8?B?dmFuZGls?=
    Replies:
    2
    Views:
    1,216
    Eliyahu Goldin
    Jan 25, 2007
  3. Replies:
    2
    Views:
    1,029
    bruce barker
    Feb 14, 2008
  4. John
    Replies:
    0
    Views:
    479
  5. Stu Sands

    Datagrid Footer data doesn't display until postback

    Stu Sands, May 3, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    186
    Stu Sands
    May 3, 2005
Loading...

Share This Page