Asked by:
Info GridView

Question
-
User-12314477 posted
Hi guys,
It's my first post.
I'm writting to ask help about a new project. I've to undestand the better model to use for the core page of this new project.
I need to build a particular grid with dinamically columns, cliccking on a cell it will open a new form with all the detail
ex:
| Company, investors | Company, investors | .... |
range time | Company, investors | Company, investors | .... |
range time | Company, investors | Company, investors | .... |
... | ... | ... | .... |
Is it possibile used gridview nested or list view + gridview?
many thanks,
Stefano
Tuesday, December 18, 2018 11:30 AM
All replies
-
User753101303 posted
Hi,
On my side I still don't fully get the kind of UI you want. This is a single company name and list of investors maybe grouped on some time information ? You'll have the same company name in each column or it could vary from one line to the next ?
I'm not sure yet a grid view is your best option. I wonder if it couldn't be shown as series of "tiles".
Tuesday, December 18, 2018 2:56 PM -
User-893317190 posted
Hi Ste81,
You could use a link in your main page and set its target to _blank to open a new form of all the detailed information.
Below is my code.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="CategoryID" DataSourceID="SqlDataSource1"> <Columns> <asp:BoundField DataField="CategoryName" HeaderText="CategoryName" SortExpression="CategoryName" /> <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /> <asp:TemplateField> <ItemTemplate> <a href='<%# "/gridview3/oneToManyExe/showDetail.aspx?id="+Eval("CategoryID") %>' target="_blank">go to detail</a> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:WingtipToysConnectionString2 %>" SelectCommand="SELECT * FROM [Categories]"></asp:SqlDataSource>
Page of child form.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ProductID" > <Columns> <asp:BoundField DataField="ProductID" HeaderText="ProductID" InsertVisible="False" ReadOnly="True" SortExpression="ProductID" /> <asp:BoundField DataField="ProductName" HeaderText="ProductName" SortExpression="ProductName" /> <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" /> <asp:TemplateField> <ItemTemplate> <asp:Image ID="Image1" runat="server" ImageUrl='<%# "/images/WingtipToys/"+Eval("ImagePath") %>' /> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice" /> </Columns>
Code behind of child page.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { int id = Request["id"] == null ? 1 : int.Parse(Request["id"]); using (SqlDataAdapter adapter = new SqlDataAdapter("select * from Products where categoryId =@id", constr)) { adapter.SelectCommand.Parameters.AddWithValue("id", id); DataTable table = new DataTable(); adapter.Fill(table); GridView1.DataSource = table; GridView1.DataBind(); } } }
The result.
If you want to use nested gridview, you could refer to the code below.
https://www.aspsnippets.com/Articles/Nested-GridView-Example-in-ASPNet-using-C-and-VBNet.aspx
Best regards,
Ackerly Xu
Wednesday, December 19, 2018 4:09 AM