473,473 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Adding row in itemtemplate for grid view

noora
2 New Member
Hi
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
  1. <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" AllowPaging="True" ShowFooter="true" DataKeyNames="userid" OnRowDataBound="GridView1_RowDataBound" OnPageIndexChanging="gridView_PageIndexChanging">
  2.             <Columns>
  3.                 <asp:TemplateField>
  4.                     <ItemTemplate>
  5.                         <tr>
  6.                             <td colspan="100%">
  7.                                 <div id="div<%# Eval("userid") %>" style="display: none; position: relative; left: 15px;
  8.                                     overflow: auto; width: 97%">
  9.                                     <asp:GridView ID="GridView2" AllowSorting="true" AutoGenerateColumns="false" runat="server" DataKeyNames="CurrentActorUID"
  10.                                         OnPageIndexChanging="GridView2_PageIndexChanging">
  11.                                          <Columns>
  12.                                             <asp:BoundField DataField="ReferenceNo" HeaderText="ReferenceNo" ReadOnly="True" />
  13.                                             <asp:BoundField DataField="Initiator" HeaderText="Requester" ReadOnly="True" ControlStyle-Width="50px" />
  14.                                             <asp:BoundField DataField="Status" HeaderText="Status" ReadOnly="True" />
  15.                                             <asp:BoundField DataField="RequestedDate" HeaderText="RequestedDate" ReadOnly="True" />
  16.                                             <asp:BoundField DataField="ServiceNo" HeaderText="ServiceNo" ReadOnly="True" />
  17.                                             <asp:BoundField DataField="Details" HeaderText="Details" ReadOnly="True" />
  18.                                         </Columns>
  19.                                     </asp:GridView>
  20.                                 </div>
  21.                             </td>
  22.                         </tr>
  23.                     </ItemTemplate>
  24.                 </asp:TemplateField>
  25.             </Columns>
  26.         </asp:GridView>
and the code behind

Expand|Select|Wrap|Line Numbers
  1. using (SqlDataAdapter mySqlAdapter1 = new SqlDataAdapter(command))
  2.             {              
  3.                 DataSet myDataSet = new DataSet();
  4.                 mySqlAdapter1.Fill(myDataSet);
  5.                 DataTable dt = new DataTable();
  6.                 mySqlAdapter1.Fill(dt);
  7.                 if (dt != null)
  8.                 {
  9.                     if (dt.Rows.Count > 0)
  10.                     { TemplateField templateField = new TemplateField();
  11.                             TemplateField uid = new TemplateField();
  12.                             uid.HeaderText = "userid";
  13.                             uid.ItemTemplate = new AddItemTemplate(ListItemType.Item, "userid");
  14.                             GridView1.Columns.Add(uid);
  15.                         for (int i = 0; i < dt.Columns.Count; i++)
  16.                         {
  17.                             BoundField boundField = new BoundField();
  18.                                 if (dt.Columns[i].ColumnName.ToString() != "userid")
  19.                                 {
  20.                                     boundField.DataField = dt.Columns[i].ColumnName.ToString();
  21.                                     boundField.HeaderText = dt.Columns[i].ColumnName.ToString();
  22.                                 }
  23.                                 GridView1.Columns.Add(boundField);
  24.                         }
  25.                     }
  26.                 }
  27.                 GridView1.DataSource = dt;
  28.                GridView1.DataBind();
  29.             }

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
Jul 29 '12 #1
0 2012

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Maheshkumar.R | last post by:
Hi groups, How to get a particular selected row ID from a grid view control where i have placed imagebutton. On click event how i can get the ROW ID ? -- Mähésh Kumär. R
0
by: Fernando Lopes | last post by:
Hi. I have a grid where i create its columns in runtime. I tried create a templatefield in this grid view. In true, i need to create a radiobutton column in my grid view. I didin't had sucess....
0
by: SimonZ | last post by:
If I have gridView and one of the columns is template cpolumn, where I have listBox in edit mode: <asp:TemplateField> <HeaderTemplate>CategorName:</HeaderTemplate> <ItemTemplate> <asp:Label...
0
by: weiwei | last post by:
Hi; I am having trouble to get variable from grid view. here is my scenario. I want to delete a row in database from web page, in additon, I also want to delete that user's directory in c:drive. ...
4
by: mosscliffe | last post by:
Dear All, I am still finding my way around Visual Web Developer, but I have hit a problem. I would like to either use a multiline gridview or a less detailed, but multi record detail view,...
12
by: brwalias | last post by:
Hi, using .net 2 sql server 2005 Here is my situation: I'm passing a variable in the url from a selection on Page A and need to display the results on the Results page be based on that...
2
by: rameshgohil | last post by:
I am using grid view and a button column in it using <itemTemplate> but I am not able to rerive cell value of a selected row from grid view. I have tried the following to methods in Row_command...
3
by: =?Utf-8?B?SXNoYW4gQmhhbGxh?= | last post by:
Hi, Am new to Asp.Net and want to try a add a combo to a grid view. Is this possible? If not is there any other control like the grid view that i can use to get the same effect? Thanks in...
1
by: John | last post by:
Hi I have a grid view bound to an SqlDataSource. One of the fields in grid view is a hyperlink field. How can I set the hyperlink field's navigationurl to the value of a field coming form the...
1
by: =?Utf-8?B?Q2hhcm1pbmdwcmk=?= | last post by:
How to set a particular column as non editable in grid view
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.