Reputation: 773
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,
Upvotes: 0
Views: 5553
Reputation: 7525
You can do the following approach:
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();
}
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 }
Upvotes: 1
Reputation: 28588
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;
}
Upvotes: 0
Reputation: 15253
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.
Upvotes: 2