Strange behavior in DataGrid

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Strange behavior in DataGrid

    Hi all,

    Hope you can give me a solution for this. I am having lot of problems with
    datagrid but like to come out with one by one.

    My main problem is, sometime datagrid disappear. Still I couldn't find a
    solution. But if you can give an answer for below mentioned one, it will
    greatly help on my work.

    when the user submit the page after some modification in the grid, I usually
    get count on grid and get the updated values like below.

    for (int i=0l; i < myGrid.Items.Count; i++)
    {
    //update part.....
    }

    but sometimes, it won't go through the loop. In order to test I add
    Response.Write(myGrid.Items.Count.ToString()) statement to the code.

    Unbelievable! sometimes this gives 0 for count even though rows were there.
    Can anyone help me on this strange behavior.

    Highly appreciate all your reply.

    Dinesh Priyankara


    Dinesh Priyankara Guest

  2. Similar Questions and Discussions

    1. Strange behavior
      The problem seems to be in c code calling ruby calling c code. ======== start test.rb puts "about to require curses" require "curses" puts...
    2. Strange behavior of $.
      Apparently $. is not always set correct (see second ruby 1liner). Is this a bug? 12:12:42 : cat -n n 1 2 3 BAR="hello" 4 12:12:47 : ruby...
    3. Strange behavior with HttpCookieCollection
      Hi, I created a simple webform, put a test button on it and implemented a click handler that looks like so: private void btnTest_Click(object...
    4. Strange behavior of DBI/DBD::Informix
      I tried sending this problem to the address specified in DBD::Informix::TechSupport (perldoc) - dbd-informix@us.ibm.com but...
    5. Why strange IF...ELSE behavior
      Hi all, I'm getting a strange result with the following IF statement: $bar = ($foo == 'last') ? true : false; In my script $foo normaly has...
  3. #2

    Default Re: Strange behavior in DataGrid

    like you said the data grid does not appear when there is no data to be
    rendered. the bug must lay in the way you are filling the datagrid with data
    from your datasource. basically it doesn't always have data and you need to
    check that it always does.
    "Dinesh Priyankara" <dinesh@dineshpriyankara.com> wrote in message
    news:O2V5GbJYDHA.2548@TK2MSFTNGP09.phx.gbl...
    > Hi all,
    >
    > Hope you can give me a solution for this. I am having lot of problems with
    > datagrid but like to come out with one by one.
    >
    > My main problem is, sometime datagrid disappear. Still I couldn't find a
    > solution. But if you can give an answer for below mentioned one, it will
    > greatly help on my work.
    >
    > when the user submit the page after some modification in the grid, I
    usually
    > get count on grid and get the updated values like below.
    >
    > for (int i=0l; i < myGrid.Items.Count; i++)
    > {
    > //update part.....
    > }
    >
    > but sometimes, it won't go through the loop. In order to test I add
    > Response.Write(myGrid.Items.Count.ToString()) statement to the code.
    >
    > Unbelievable! sometimes this gives 0 for count even though rows were
    there.
    > Can anyone help me on this strange behavior.
    >
    > Highly appreciate all your reply.
    >
    > Dinesh Priyankara
    >
    >

    Alvin Bruney Guest

  4. #3

    Default Re: Strange behavior in DataGrid

    "Dinesh Priyankara" <dinesh@dineshpriyankara.com> writes:
    > My main problem is, sometime datagrid disappear. Still I couldn't find a
    > solution. But if you can give an answer for below mentioned one, it will
    > greatly help on my work.
    >
    > when the user submit the page after some modification in the grid, I usually
    > get count on grid and get the updated values like below.
    >
    > for (int i=0l; i < myGrid.Items.Count; i++)
    > {
    > //update part.....
    > }
    >
    > but sometimes, it won't go through the loop. In order to test I add
    > Response.Write(myGrid.Items.Count.ToString()) statement to the code.
    Where do you put the above logic?

    --
    Peter Wu
    Powered by Microsoft Windows XP [Version 5.1.2600]
    Peter Wu Guest

  5. #4

    Default Re: Strange behavior in DataGrid


    This is the part of code in one of my forms


    html code for grid:
    <asp:datagrid id="dgdHolidayDetails" runat="server" Width="526px"
    CellPadding="3" DataKeyField="Id" AutoGenerateColumns="False">
    <AlternatingItemStyle CssClass="TableBlueRowVer11"></AlternatingItemStyle>
    <ItemStyle CssClass="TableWhiteRowVer11"></ItemStyle>
    <HeaderStyle Height="25px" CssClass="TableHed"></HeaderStyle>
    <Columns>
    <asp:BoundColumn Visible="False" DataField="Id" HeaderText="Id">
    <HeaderStyle Width="10px"></HeaderStyle>
    </asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Day">
    <HeaderStyle HorizontalAlign="Center" Width="60px"></HeaderStyle>
    <ItemTemplate>
    <asp:Label id=lblDate runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Date","{0:d}") %>'>
    </asp:Label>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Type">
    <HeaderStyle Wrap="False" HorizontalAlign="Center"
    Width="120px"></HeaderStyle>
    <ItemTemplate>
    <asp:Label id=lblType runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.HolidayType") %>'>
    </asp:Label>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Description">
    <HeaderStyle HorizontalAlign="Center"
    Width="200px"></HeaderStyle>
    <ItemTemplate>
    <asp:Label id=lblDesc runat="server" Text='<%#
    DataBinder.Eval(Container, "DataItem.Description") %>'>
    </asp:Label>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:TemplateColumn>
    <HeaderStyle Width="45px"></HeaderStyle>
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:LinkButton id="LinkButton2" runat="server"
    Text="Edit" CausesValidation="false"
    CommandName="Edit"></asp:LinkButton>&nbsp;
    <asp:LinkButton id="lbnDel" runat="server"
    CommandName="Delete">Delete</asp:LinkButton>
    </ItemTemplate>
    <EditItemTemplate>
    <asp:LinkButton id="LinkButton4" runat="server"
    Text="Update" CommandName="Update"></asp:LinkButton>&nbsp;
    <asp:LinkButton id="LinkButton3" runat="server"
    Text="Cancel" CausesValidation="false"
    CommandName="Cancel"></asp:LinkButton>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:datagrid>

    in code behind:
    The FillHolidayDetailGird is the method which load data into grid
    private void Page_Load(object sender, System.EventArgs e)
    {
    if (!IsPostBack)
    {
    FillHolidayDetailGird();
    }
    }

    private void FillHolidayDetailGird()
    {
    dgdHolidayDetails.DataSource=Com.Holiday.getHolida yDetail();
    dgdHolidayDetails.DataBind();
    }

    This is the editcommand event for the grid.
    When the edit link is clicked in the grid, it will load some related data
    from the grid according to the key (keyvalue in grid) and place all on text
    boxes that are seperated from the grid..
    After that user can submit the changes. This will done through the another
    method that is writtern for submit button. In that method viewstate value is
    used.

    private void dgdHolidayDetails_EditCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    ViewState["ModeEdit"]=true;
    ViewState["HolidayKey"]=int.Parse(e.Item.Cells[0].Text);

    ddlHolidayType.SelectedIndex =
    getSelectedHolidayType(((Label)e.Item.FindControl( "lblType")).Text);
    txbHolidayDesc.Text =
    Convert.ToString(((Label)e.Item.FindControl("lblDe sc")).Text);

    LinkButton linkbtn = new LinkButton();
    linkbtn = ((LinkButton) e.Item.Cells[0].FindControl("lbnDel"));
    linkbtn.Enabled = false;
    }

    SOMETIMES, if I click on edit link in the grid, it won't place values to
    text boxes and grid also disappear. If I refreshed the page (F5), then the
    correct data is loaded to the text boxes and grid is appeared.


    Highly appreciate if you can help me on this as I am stuck with my project.
    Almost all forms, I am having this problem.

    Dinesh



    "Peter Wu" <peterwu@hotmail.com> wrote in message
    news:r83qhp1e.fsf@hotmail.com...
    > "Dinesh Priyankara" <dinesh@dineshpriyankara.com> writes:
    >
    > > My main problem is, sometime datagrid disappear. Still I couldn't find a
    > > solution. But if you can give an answer for below mentioned one, it will
    > > greatly help on my work.
    > >
    > > when the user submit the page after some modification in the grid, I
    usually
    > > get count on grid and get the updated values like below.
    > >
    > > for (int i=0l; i < myGrid.Items.Count; i++)
    > > {
    > > //update part.....
    > > }
    > >
    > > but sometimes, it won't go through the loop. In order to test I add
    > > Response.Write(myGrid.Items.Count.ToString()) statement to the code.
    >
    > Where do you put the above logic?
    >
    > --
    > Peter Wu
    > Powered by Microsoft Windows XP [Version 5.1.2600]

    Dinesh Priyankara Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139