I'm trying add a gridview dynamically (lets call this gridview2) to existing gridview (lets call this gridview1) added through .aspx page.
What i'm trying to do is: Depending upon the content of the row (more specifically invoice number displayed in the cell-1 with zero based indexing) displayed in "gridview1" i'm filtering data from a list and displaying the data in "gridview2".
I'm doing some terrible mistake somewhere or my approach should be fundamentally wrong.
Below is the code for gridview1 added in .aspx page.
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="ClickingBtn_Click" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Date Of Transaction"
HeaderText="Date Of Transaction" SortExpression="Date Of Transaction" />
<asp:BoundField DataField="Invoice Number" HeaderText="Invoice Number"
SortExpression="Invoice Number" />
<asp:BoundField DataField="totalAmount" HeaderText="totalAmount"
ReadOnly="True" SortExpression="totalAmount" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ComponentDBConnectionString %>"
SelectCommand="SelectUserPreviousHistory" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter DefaultValue="duran" Name="userName" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
This is fetching the data as shown here: here
And then I'm trying to add another gridview depending upon the unique invoice number displayed in each row by following code:
foreach (GridViewRow gridviewrow in GridView1.Rows)
{
GridView gridView2 = new GridView();
gridView2.AutoGenerateColumns = true;
String x = gridviewrow.Cells[1].Text; //IT FETCHES THE INVOICE NUMBER FROM EACH ROW
softwareTitlesList = SoftwareListRetrieve(); //lIST OF ALL THE SOFTWARE TITLES ADDED TO LIST
ArrayList titles = new ArrayList();
foreach (SoftwareTitles softwareTitle in softwareTitlesList)
{
if (softwareTitle.InvoiceNumber.Contains(x))
titles.Add(softwareTitle.SoftwareTitle); //ADDING ONLY THOSE TITLES THAT MATCH THAT PARTICULAR INVOICE NUMBER
}
gridView2.DataSource = titles;
gridView2.DataBind();
}
But nothing seems to be happening. What is wrong with this ?
Please help me
BTW I'm using asp.net/c# visualstudio 2010. And i'm not using LINQ in my project and the database is sql server 2005
Thanks in anticipation