adding rows to GridView at runtime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shrikanthn
    New Member
    • Jul 2008
    • 3

    adding rows to GridView at runtime

    Hi All,
    i am adding some data into GridView (adding 4 to 5 rows) at runtime in asp.net page using c#. but getting outofbond error.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Let's see the code you are using.
    Probably a problem with one of your index accesses.

    Comment

    • shrikanthn
      New Member
      • Jul 2008
      • 3

      #3
      Originally posted by r035198x
      Let's see the code you are using.
      Probably a problem with one of your index accesses.
      Hope following code help you to get my problem.......

      *****In ASPX Page*********** ******
      Code:
       <asp:GridView ID="GridView1" runat="server" CellPadding="3" BackColor="#DEBA84" BorderColor="#DEBA84"
                          BorderStyle="None" BorderWidth="1px" CellSpacing="2" Width="539px" Height="149px">
                          <FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
                          <RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
                          <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
                          <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
                          <HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
                          <Columns>
                              <asp:BoundField HeaderText="Date" />
                              <asp:BoundField HeaderText="Schedule" />
                          </Columns>
                          <EditRowStyle BorderStyle="Dotted" />
                      </asp:GridView>
      **************I n ASPX.CS page*********** **
      Code:
      for (int i = 0; i <= countDays; i++)
                  { 
                   dt = dt.AddDays(i);     //dt is datetime type data
                   GridView1.Rows[i].Cells[0].Text= dt.ToString();                  
                   GridView1.Rows[i].Cells[1].Text = "str"
                 }
      Last edited by Curtis Rutland; Jul 30 '08, 02:30 PM. Reason: Added Code Tags - Please use the # button

      Comment

      Working...