开发者

Adding muliple rows inside of Gridview row

I am working with Gridview control and I am also adding radio button to each row in ASP .NET. Here is something that I would like to accomplish but I am not sure how this should done. The problem is that I have add a muliple datarow insie of t开发者_Python百科he each gridview. Something like below.

Adding muliple rows inside of Gridview row

So, some cases I have add a row with two rows like the example. And, the ID eventurally will be radio button where user can click. Is there any way i can accomplish this?

Thank your help.


For the RadioButton, you will need to use the

<asp:TemplateField>
   <ItemTemplate>
      <asp:RadioButton ID="RadioButton1" runat="server" />
   </ItemTemplate>
</asp:TemplateField>

Depending on the data which you are binding to the GridView, e.g. List of objects within Lists of objects, you can bind Gridview's within a gridview using Container.DataItem.

<asp:TemplateField>
   <ItemTemplate>          
       <asp:GridView ID="GridView2" runat="server" DataSource='<%((Relationships)Container.DataItem).People %>'>
           <Columns>                            
           </Columns>
       </asp:GridView>
   </ItemTemplate>
</asp:TemplateField>


It's a bit of an odd requirement, but I have done something similar in the past where I added a second row for a notes box for each row, because it would have been too wide to sensibly fit on the current row.

During your RowDataBound event try something like this:

    GridView x = (GridView)sender;

    if (e.Row.RowType == DataControlRowType.DataRow && x.EditIndex == e.Row.RowIndex)
    {
        TextBox notes = (TextBox)e.Row.Cells[0].Controls[0];
        notes.Height = // some height
        notes.Width = // some width
        notes.TextMode = TextBoxMode.MultiLine;
        e.Row.Cells[0].Controls.Clear();
        GridViewRow row = new GridViewRow(0, 0, DataControlRowType.DataRow, DataControlRowState.Normal);
        TableCell cell = new TableCell();
        cell.ColumnSpan = // gridview columns count;
        cell.Controls.Add(notes);
        row.Cells.Add(cell);
        x.Controls[0].Controls.AddAt(x.EditIndex + 2, row);
    }

note, this is grabbing an existing bound TextBox from the 23rd column and copying it into a new row, then it is being removed from the original cell. Additionally, the notes box was only shown on the row being edited, hence: && x.EditIndex == e.Row.RowIndex and x.Controls[0].Controls.AddAt(x.EditIndex + 2, row);

You'll probably just want the new GridViewRow and new TableCell parts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜