DataGrid OnItemDataBound problem in APS.NET C#

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default DataGrid OnItemDataBound problem in APS.NET C#

    I have 2 different data grids that are storing data from
    two different tables in my data base:

    My datagrid starts like this:
    <asp:DataGrid id="DataGridGPA" runat="server"
    OnItemDataBound="bindGPAList" ...


    My bindGPAList looks like this:
    public void bindGPAList(object sender,
    DataGridItemEventArgs e) {
    if(e.Item.ItemType == ListItemType.EditItem) {
    DropDownList Dl = (DropDownList)
    e.Item.FindControl("dropDownListGPASemester");
    Dl.SelectedIndex = Dl.Items.IndexOf(
    Dl.Items.FindByValue( DataBinder.Eval
    (e.Item.DataItem, "theSemester").ToString() ) );

    }
    if((e.Item.ItemType == ListItemType.Item) ||
    (e.Item.ItemType == ListItemType.AlternatingItem)) {

    if(DataBinder.Eval
    (e.Item.DataItem, "theSemester").ToString() == "1")
    e.Item.Cells[0].Text = "Winter";
    else if(DataBinder.Eval
    (e.Item.DataItem, "theSemester").ToString() == "2")
    e.Item.Cells[0].Text = "Spring";
    else if(DataBinder.Eval
    (e.Item.DataItem, "theSemester").ToString() == "3")
    e.Item.Cells[0].Text = "Summer";
    else if(DataBinder.Eval
    (e.Item.DataItem, "theSemester").ToString() == "4")
    e.Item.Cells[0].Text = "Fall";
    }


    When the page loads, Winter, Summer... semesters are
    shown in the cells. Whenever someone clicks on edit or
    update... in the second grid, the text Winter, Summer....
    from the first datagrid cells disapears, until the user
    comes back and clicks on edit link of the first. What is
    causing the mysterious disapearance of the data in the
    first grid column? Thank you.
    Steven Guest

  2. Similar Questions and Discussions

    1. OnItemDataBound not called
      Hello, I have overriden the OnItemDataCommand in my component, but it is never called. What I am doing wrong? I defined it like this: ...
    2. OnItemDataBound Problem
      Hi, I created a DataGrid programmatically, my problem is that I dont know how to associate a function with the OnItemDataBound event of the...
    3. OnItemDataBound Master Detail
      Hello, I use the OnItemDataBound event to dynamically Create a Master Detail Relationship between two DataGrids. How would I go about storing...
    4. DataGrid - OnItemDataBound - Selected
      Try putting some of this into the item created event. "Trevor Oakley via .NET 247" <anonymous@dotnet247.com> wrote in message...
    5. URGENT question about binding collection to a datagrid onitemdatabound
      The following code works to hide specific columns before they are bound to a datagrid that has "autogeneratecolumns=true" enabled. My question is:...
  3. #2

    Default Re: DataGrid OnItemDataBound problem in APS.NET C#

    Hi Steven,

    Is the EnableViewState control set to "true" ? if no, try that.
    where do you bind the datagrid ? try page_load!

    I hope this can help...


    Simon
    Simon 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