locked
CSS Friendly Control Adapters not support dynamically created rows in GridView? RRS feed

  • Question

  • User137689738 posted
    I have a dynamically created row in GridView control. But it will not appear when I use CSS Friendly Control Adapter. I have to set

    adapterenabled=false to make it work. But I will loss all the table style in this way. Any better ideas to solve this problem?

    This is the code behind to add a new row.

    protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)

    {

    GridViewRow insertedRow = new GridViewRow(GridView3.Rows.Count, GridView3.Rows.Count, DataControlRowType.DataRow, DataControlRowState.Normal);

    TableCell cell = new TableCell();

    cell.Text = " hello";

    cell.ColumnSpan = GridView3.Columns.Count;

    insertedRow.Cells.Add(cell);

    GridView3.Controls[0].Controls.AddAt(GridView3.Controls[0].Controls.Count - 1, insertedRow);

    }

    Tuesday, August 7, 2007 3:35 AM

Answers

  • User137689738 posted

     I added   ShowFooter="True"  for my gridview and added a blank template for footer

     <asp:GridView ID="GridView3" runat="server"
                            DataKeyNames="photo_ID"
                            DataSourceID="ObjectDataSource3" Style=""
                            CssSelectorClass="PrettyGridView" 
                            ShowFooter="True" OnRowCommand="GridView3_RowCommand"
                             >
                              <Columns>
                            ........

                             ...
                             <asp:TemplateField HeaderText="% Return" >
                                 <FooterTemplate>
                                   
                                 </FooterTemplate>
                             </asp:TemplateField>

                          </Columns>  
                           <FooterStyle CssClass="CELL_footer" />     
                        </asp:GridView>  

     

    And in the RowDataBound Event, I can dynamically generate the content of the footer: 

     protected void GridView3_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.Footer)  //draw table footer
            {
               
                double _total_return = Convert.ToDouble(Total_label.Text);
                String formated_total = string.Format("{0:P2}", _total_return);
               
                    e.Row.Cells[7].Text = formated_total ;
               }

     

    This method only for add a new row at the bottom of Gridview.

    Anthoer trickey method required If you want to add subheaders in the  Gridview with CSS friendly adpater. Basically you need reformat the content of the first Cell text in the row.  But I am not sure it is a good solution.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 22, 2007 11:42 PM