0

I am currently working on the development of news portal website in asp.net. I have created a table in sql server 2008 with parameters (NewsId, NewsTitle, NewsDetails, NewsCategory). I am now able to dynamically retrieve the NewsTitle from the database and displaying it in my aspx page. Now I want to pass the NewsId for that particular NewsTitle and then retrieve the NewsDetails in a separate aspx page. What is the best thing to do this in ASP.NET? I don't want to create new aspx pages every time a link to the NewsTitle is clicked, rather I am interested to use the same Details page and pass different ID parameters?

regards,

2
  • well then pass the parameter via session or query string ! ! Commented Apr 17, 2012 at 5:50
  • learn to use database classes defined in C# (if you use ASP.NET with C#) or VB.NET. Get a book and read it. There will provide many examples using databases. Commented Apr 17, 2012 at 5:51

3 Answers 3

2

I'd keep them both on the same page and employ a master-details pattern using something like panels to toggle the visibility:

http://leedumond.com/blog/master-detail-editing-inserting-deleting-with-a-listview-and-detailsview/

This will give you the basic idea; the sample linked to shows both, but as I said it is a simple matter to toggle them on and off on the click of a button.

Sign up to request clarification or add additional context in comments.

Comments

1

You can do the following approach:

  1. Take HyperLink in a Gridview to show a NewsTitle:

    <asp:GridView ID="GridView1" runat="server">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                     <asp:HyperLink runat="server" ID="hl" NavigateUrl='<%#"NewsDetails.aspx?Newsid="+ Eval("NewsId") %>' Text='<%# Eval("NewsTitle") %>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    Bind the GridView datasource in code behind:

    protected void getNewsDetails()
    {
        DataTable dtNewsDetails = new DataTable();
        //retrieve data from database into the DataTable
        GridView1.DataSource = dtNewsDetails;
        GridView1.DataBind();
    }
    
  2. Now as GridView HyperLink will navigate to the NewsDetails.aspx with a NewsId as querystring, show the details accordingly in a NewsDetails.aspx page:

    protected void Page_Load(object sender, EventArgs e) { string Newsid = Request.QueryString["Newsid"].ToString(); //show the details from database using Newsid }

3 Comments

Thank you Ashwin. This seems interesting and I will let you know once i tried it.
It is working fine now. I followed your guidelines except that I used FormView instead of GridView to display the NewsTitle and NewsDetails. Thank you once again
I just given an idea! please mark as an answer if it worked for you.
0

You can add a textBox with visible attribute set as False and when you retrieve the NewsDetails set it to textBox and set it visibility to True;

<asp:TextBox ID="NewsDetails" runat="server" TextMode="MultiLine" 
                        Height="30px" Width="200px" Visible="False" />

and

void GetNewsDetails()
{
NewsDetails.Text=GetDetailsQuery;
NewsDetails.Visible=True;
}

2 Comments

Why would you display news in a TextBox ?
You can use any control like label that is just an example for displaying on the same page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.