i was facing problem in my nested gridviews, and thank god i solved it, but with minor issues in the look and feel of the grid view
this is an aspx code
Expand|Select|Wrap|Line Numbers
- <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="True" ShowFooter="true" DataKeyNames="userid" OnRowDataBound="GridView1_RowDataBound" OnPageIndexChanging="gridView_PageIndexChanging">
- <Columns>
- <asp:TemplateField>
- <ItemTemplate>
- <tr>
- <td colspan="100%">
- <div id="div<%# Eval("userid") %>" style="display: none; position: relative; left: 15px;
- overflow: auto; width: 97%">
- <asp:GridView ID="GridView2" AllowSorting="true" AutoGenerateColumns="false" runat="server" DataKeyNames="CurrentActorUID"
- OnPageIndexChanging="GridView2_PageIndexChanging">
- <Columns>
- <asp:BoundField DataField="ReferenceNo" HeaderText="ReferenceNo" ReadOnly="True" />
- <asp:BoundField DataField="Initiator" HeaderText="Requester" ReadOnly="True" ControlStyle-Width="50px" />
- <asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True" />
- <asp:BoundField DataField="RequestedDate" HeaderText="RequestedDate" ReadOnly="True" />
- <asp:BoundField DataField="ServiceNo" HeaderText="ServiceNo" ReadOnly="True" />
- <asp:BoundField DataField="Details" HeaderText="Details" ReadOnly="True" />
- </Columns>
- </asp:GridView>
- </div>
- </td>
- </tr>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- </asp:GridView>
Expand|Select|Wrap|Line Numbers
- using (SqlDataAdapter mySqlAdapter1 = new SqlDataAdapter(command))
- {
- DataSet myDataSet = new DataSet();
- mySqlAdapter1.Fill(myDataSet);
- DataTable dt = new DataTable();
- mySqlAdapter1.Fill(dt);
- if (dt != null)
- {
- if (dt.Rows.Count > 0)
- { TemplateField templateField = new TemplateField();
- TemplateField uid = new TemplateField();
- uid.HeaderText = "userid";
- uid.ItemTemplate = new AddItemTemplate(ListItemType.Item, "userid");
- GridView1.Columns.Add(uid);
- for (int i = 0; i < dt.Columns.Count; i++)
- {
- BoundField boundField = new BoundField();
- if (dt.Columns[i].ColumnName.ToString() != "userid")
- {
- boundField.DataField = dt.Columns[i].ColumnName.ToString();
- boundField.HeaderText = dt.Columns[i].ColumnName.ToString();
- }
- GridView1.Columns.Add(boundField);
- }
- }
- }
- GridView1.DataSource = dt;
- GridView1.DataBind();
- }
notice there are <tr><td colspan="100%"> under the itemTemplate for the child gridview
when i run the report, the itemtemplate column was created for the userid but the column header is shifted to the right that affect the look of the table. also when i click on userid the <div> tag should be visible below and in the example above i am getting the <div> above the clicked userid and this is wrong that's mean the the <tr> is create above.
so how can i solve this problem? any suggestions
i thought of using repeater, and adding this repeater dynamically but i don't know how