Problem in OnItemDataBound

Discussion in 'ASP .Net' started by yme, Sep 13, 2007.

  1. yme

    yme Guest

    Hi guys,

    I have a datagrid with 4 columns, in the 2nd column I have a Label and
    in the 4th a DropDown.

    As I want to change the content of the DropDown according with the
    content of the label I've built a function that executes on
    ItemDataBound:

    protected void dgCriteriosDB(object sender, DataGridItemEventArgs e){
    //identification for the criteria
    int idCriterio = 0;

    if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
    ListItemType.AlternatingItem))
    {
    Label lbl_idCriterio =
    (Label)e.Item.FindControl("lbl_idCriterio");
    Label lblCriterio = (Label)e.Item.FindControl("lbl_criterio");
    idCriterio = System.Convert.ToInt32(lbl_idCriterio.Text);
    //change the select statement
    src_subCriteriosAval.SelectCommand="SELECT [id_subcriterio],
    [id_criterio], [desc_sub_criterio], [imp_relativa], [ordem] FROM
    [MSP_PMO_Scoring_SubCriteriosAvaliacao] WHERE ([id_criterio]
    ="+idCriterio+")";
    /apply the select statement
    DropDownList dg3 =
    (DropDownList)e.Item.FindControl("drpSubCriterios");
    dg3.DataSourceID = "src_subCriteriosAval";
    dg3.DataTextField = "desc_sub_criterio";
    dg3.DataValueField ="imp_relativa";
    dg3.DataBind();
    }

    }

    The function seems to be woorking well but if it fires for each row,
    why does it change all the previous records?
    yme, Sep 13, 2007
    #1
    1. Advertising

  2. yme

    Sam Guest

    What do you mean by "why does it change all the previous records"? Did you
    mean that all previous records become null/empty or blank space?

    Sam

    "yme" <> wrote in message
    news:...
    > Hi guys,
    >
    > I have a datagrid with 4 columns, in the 2nd column I have a Label and
    > in the 4th a DropDown.
    >
    > As I want to change the content of the DropDown according with the
    > content of the label I've built a function that executes on
    > ItemDataBound:
    >
    > protected void dgCriteriosDB(object sender, DataGridItemEventArgs e){
    > //identification for the criteria
    > int idCriterio = 0;
    >
    > if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
    > ListItemType.AlternatingItem))
    > {
    > Label lbl_idCriterio =
    > (Label)e.Item.FindControl("lbl_idCriterio");
    > Label lblCriterio = (Label)e.Item.FindControl("lbl_criterio");
    > idCriterio = System.Convert.ToInt32(lbl_idCriterio.Text);
    > //change the select statement
    > src_subCriteriosAval.SelectCommand="SELECT [id_subcriterio],
    > [id_criterio], [desc_sub_criterio], [imp_relativa], [ordem] FROM
    > [MSP_PMO_Scoring_SubCriteriosAvaliacao] WHERE ([id_criterio]
    > ="+idCriterio+")";
    > /apply the select statement
    > DropDownList dg3 =
    > (DropDownList)e.Item.FindControl("drpSubCriterios");
    > dg3.DataSourceID = "src_subCriteriosAval";
    > dg3.DataTextField = "desc_sub_criterio";
    > dg3.DataValueField ="imp_relativa";
    > dg3.DataBind();
    > }
    >
    > }
    >
    > The function seems to be woorking well but if it fires for each row,
    > why does it change all the previous records?
    >
    Sam, Sep 14, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio D'Ottavio
    Replies:
    1
    Views:
    2,696
    Antonio D'Ottavio
    Sep 19, 2005
  2. Steven
    Replies:
    1
    Views:
    1,626
    Simon
    Jul 9, 2003
  3. ibiza
    Replies:
    2
    Views:
    5,635
    ibiza
    Feb 1, 2006
  4. Mikeon

    OnItemDataBound problem

    Mikeon, Mar 22, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,473
    Mikeon
    Mar 22, 2006
  5. Simang

    OnItemDataBound Problem

    Simang, Jan 28, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    93
    Simang
    Jan 28, 2005
Loading...

Share This Page