Hi Experts,
I am looking for some guidance on my asp.net C# project in reference to Master details page.
Not so long ago I posted something similar to this post but I didn't provide enough information and as a result I didn't get what I was looking for. My apology.
My master page (page1.aspx) has 2 columns: Column1 and Column3. I am using Gridivew control.
My details page (page1_Details.aspx) has 3 columns: Column1, Column2, and Column3. I am using DetailsView control.
All the records under Column1 on Master page are hyperlink.
When I select a record under Column1 on Master page, I would like to see the details page that has other information pertaining to that particular record that I select from Column1
I can handle the Master page and details page except a minor issue that I can't figure out by myself.
The issue is that one of my columns (Column2) on the Details page didn't display all available values.
In other words, in the example below, Column2 has 3 values (Green, Red, Yellow) for a particular record and only first value (Green) is displayed.
My data in SQL is like this:
======================================================================================
Select * from Table1
Column1 Column2 Column3
Apple Green Apple is a great fruit
Apple Red Apple is a great fruit
Apple Yellow Apple is a great fruit
Tomatoes Red Tomatoes is a great fruit
Tomatoes Yellow Tomatoes is a great fruit
I want the output for Details page like this:
Column1 Apple
Column2 Green
Red
Yellow
Column3 Apple is a great fruit
My current output on Details page is like this if I select 'Apple' hyperlink from Master page (page1.aspx). NOTE: It didn't display Red and Yellow
Column1 Apple
Column2 Green
Column3 Apple is a great fruit
I included my code for Page1 and Page1_Details web page for your information.
=========================================================================================
Page1.aspx and code behind
Note: In the SQL query below I didn't include Column2 (this is the column that has multiple values).
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CssClass="gridview" AlternatingRowStyle-CssClass="even">
<Columns>
<asp:BoundField DataField="Column1" HeaderText="Column1_Name" ItemStyle-wrap="false" SortExpression="Column1" />
<asp:TemplateField HeaderText="Header1">
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" runat="server" Text='<%# Eval("Column2") %>' Target="_xmlwindow"
NavigateUrl='<%# "~/Page1_Details.aspx?Column2=" + Server.UrlEncode(Eval("Column2").ToString()) %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
code behind
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlDataSource mySqlDataSource = new SqlDataSource();
mySqlDataSource.ID = "mySqlDataSource";
this.Page.Controls.Add(mySqlDataSource);
mySqlDataSource.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DB_Conn_Str"].ConnectionString;
mySqlDataSource.SelectCommand = "SELECT DISTINCT Column1, Column3 FROM Table1";
GridView1.DataSource = mySqlDataSource;
GridView1.DataBind();
}
}
=========================================================================================
Page1_Details.aspx
NOTE: In the SQL query below I included Column2 (this is the column that has multiple values)
<asp:DetailsView ID ="DetailsView" runat="server" AutoGenerateRows="false" AllowPaging="false"
CssClass="gridview" AlternatingRowStyle-CssClass="even"
BorderWidth="1px" DataSourceID ="SQLDataSource1">
<Fields>
<asp:BoundField DataField="Column1" HeaderText="Column1" SortExpression="Column1" />
<asp:BoundField DataField="Column3" HeaderText="Column2" SortExpression="Column2" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID ="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:OrdersConnectionStringProduction %>"
SelectCommand ="SELECT DISTINCT Column1, Column2 FROM Table_Details WHERE Column1=@Column1">
<SelectParameters>
<asp:QueryStringParameter Name ="Column1" QueryStringField="Column1" />
</SelectParameters>
</asp:SqlDataSource>
Thanks so much in advance.