DataGrid_ItemCommand

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mg

    #1

    DataGrid_ItemCommand

    I have a DataGrid with 2 Button Columns of type LinkButton
    in a WebForm.

    The DataGrid is populated:

    private void Page_Load(objec t sender, System.EventArg s e)
    {
    if (! IsPostBack)
    {
    DataAdapter1.Fi ll(dataSet11);
    Page.DataBind() ;
    }
    }


    I'm able to detect which column was selected by clicking
    on one column and seeing "LEFT" displayed or the other
    column and seeing "RIGHT" displayed in a Label. But, I'm
    not able to get the data in an individual cell. That
    is, "e.Item.Cel ls[0].Text" brings back nothing. [Clues?
    e.Item.Cells.To String()
    returns "System.Web.UI. WebControls.Tab leCellCollectio n"
    and e.Item.Cells[0].ToString()
    returns "System.Web.UI. WebControls.Tab leCell"]

    private void DataGrid1_ItemC ommand(object source,
    System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
    {
    if (e.CommandName == "Select1")
    Label1.Text = e.Item.Cells[0].Text; // returns nothing
    //Label1.Text = "LEFT";
    }
    else
    { {
    Label1.Text = e.Item.Cells[1].Text; // returns nothing
    //Label1.Text = "RIGHT";
    }
    }

    How can I see the data contents of an individual cell of
    the DataGrid?
  • Daniel Bass

    #2
    Re: DataGrid_ItemCo mmand

    instead of e.Item.Cells[0].Text, which is only really valid for bound
    columns, you need to get the button text...

    try:
    Dim linkbtnCRID As LinkButton = e.Item.Cells(2) .Controls(0)
    Dim szCRID = linkbtnCRID.Tex t


    good luck.

    "mg" <mg@theworld.co m> wrote in message
    news:09be01c352 9b$25710c00$a30 1280a@phx.gbl.. .[color=blue]
    > I have a DataGrid with 2 Button Columns of type LinkButton
    > in a WebForm.
    >
    > The DataGrid is populated:
    >
    > private void Page_Load(objec t sender, System.EventArg s e)
    > {
    > if (! IsPostBack)
    > {
    > DataAdapter1.Fi ll(dataSet11);
    > Page.DataBind() ;
    > }
    > }
    >
    >
    > I'm able to detect which column was selected by clicking
    > on one column and seeing "LEFT" displayed or the other
    > column and seeing "RIGHT" displayed in a Label. But, I'm
    > not able to get the data in an individual cell. That
    > is, "e.Item.Cel ls[0].Text" brings back nothing. [Clues?
    > e.Item.Cells.To String()
    > returns "System.Web.UI. WebControls.Tab leCellCollectio n"
    > and e.Item.Cells[0].ToString()
    > returns "System.Web.UI. WebControls.Tab leCell"]
    >
    > private void DataGrid1_ItemC ommand(object source,
    > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
    > {
    > if (e.CommandName == "Select1")
    > Label1.Text = e.Item.Cells[0].Text; // returns nothing
    > //Label1.Text = "LEFT";
    > }
    > else
    > { {
    > Label1.Text = e.Item.Cells[1].Text; // returns nothing
    > //Label1.Text = "RIGHT";
    > }
    > }
    >
    > How can I see the data contents of an individual cell of
    > the DataGrid?[/color]


    Comment

    • Daniel Bass

      #3
      Re: DataGrid_ItemCo mmand

      obviously in the example text given you need to change your cells(2) to
      cells(X) where X is the column number...

      "Daniel Bass" <danielbassNOJU NK@MAILpostmast er.co.uk> wrote in message
      news:%23BSYMypU DHA.1832@TK2MSF TNGP09.phx.gbl. ..[color=blue]
      > instead of e.Item.Cells[0].Text, which is only really valid for bound
      > columns, you need to get the button text...
      >
      > try:
      > Dim linkbtnCRID As LinkButton = e.Item.Cells(2) .Controls(0)
      > Dim szCRID = linkbtnCRID.Tex t
      >
      >
      > good luck.
      >
      > "mg" <mg@theworld.co m> wrote in message
      > news:09be01c352 9b$25710c00$a30 1280a@phx.gbl.. .[color=green]
      > > I have a DataGrid with 2 Button Columns of type LinkButton
      > > in a WebForm.
      > >
      > > The DataGrid is populated:
      > >
      > > private void Page_Load(objec t sender, System.EventArg s e)
      > > {
      > > if (! IsPostBack)
      > > {
      > > DataAdapter1.Fi ll(dataSet11);
      > > Page.DataBind() ;
      > > }
      > > }
      > >
      > >
      > > I'm able to detect which column was selected by clicking
      > > on one column and seeing "LEFT" displayed or the other
      > > column and seeing "RIGHT" displayed in a Label. But, I'm
      > > not able to get the data in an individual cell. That
      > > is, "e.Item.Cel ls[0].Text" brings back nothing. [Clues?
      > > e.Item.Cells.To String()
      > > returns "System.Web.UI. WebControls.Tab leCellCollectio n"
      > > and e.Item.Cells[0].ToString()
      > > returns "System.Web.UI. WebControls.Tab leCell"]
      > >
      > > private void DataGrid1_ItemC ommand(object source,
      > > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
      > > {
      > > if (e.CommandName == "Select1")
      > > Label1.Text = e.Item.Cells[0].Text; // returns nothing
      > > //Label1.Text = "LEFT";
      > > }
      > > else
      > > { {
      > > Label1.Text = e.Item.Cells[1].Text; // returns nothing
      > > //Label1.Text = "RIGHT";
      > > }
      > > }
      > >
      > > How can I see the data contents of an individual cell of
      > > the DataGrid?[/color]
      >
      >[/color]


      Comment

      • mg

        #4
        Re: DataGrid_ItemCo mmand

        Thanks!
        [color=blue]
        >-----Original Message-----
        >obviously in the example text given you need to change[/color]
        your cells(2) to[color=blue]
        >cells(X) where X is the column number...
        >
        >"Daniel Bass" <danielbassNOJU NK@MAILpostmast er.co.uk>[/color]
        wrote in message[color=blue]
        >news:%23BSYMyp UDHA.1832@TK2MS FTNGP09.phx.gbl ...[color=green]
        >> instead of e.Item.Cells[0].Text, which is only really[/color][/color]
        valid for bound[color=blue][color=green]
        >> columns, you need to get the button text...
        >>
        >> try:
        >> Dim linkbtnCRID As LinkButton = e.Item.Cells(2) .Controls[/color][/color]
        (0)[color=blue][color=green]
        >> Dim szCRID = linkbtnCRID.Tex t
        >>
        >>
        >> good luck.
        >>
        >> "mg" <mg@theworld.co m> wrote in message
        >> news:09be01c352 9b$25710c00$a30 1280a@phx.gbl.. .[color=darkred]
        >> > I have a DataGrid with 2 Button Columns of type[/color][/color][/color]
        LinkButton[color=blue][color=green][color=darkred]
        >> > in a WebForm.
        >> >
        >> > The DataGrid is populated:
        >> >
        >> > private void Page_Load(objec t sender,[/color][/color][/color]
        System.EventArg s e)[color=blue][color=green][color=darkred]
        >> > {
        >> > if (! IsPostBack)
        >> > {
        >> > DataAdapter1.Fi ll(dataSet11);
        >> > Page.DataBind() ;
        >> > }
        >> > }
        >> >
        >> >
        >> > I'm able to detect which column was selected by[/color][/color][/color]
        clicking[color=blue][color=green][color=darkred]
        >> > on one column and seeing "LEFT" displayed or the other
        >> > column and seeing "RIGHT" displayed in a Label. But,[/color][/color][/color]
        I'm[color=blue][color=green][color=darkred]
        >> > not able to get the data in an individual cell. That
        >> > is, "e.Item.Cel ls[0].Text" brings back nothing.[/color][/color][/color]
        [Clues?[color=blue][color=green][color=darkred]
        >> > e.Item.Cells.To String()
        >> >[/color][/color][/color]
        returns "System.Web.UI. WebControls.Tab leCellCollectio n"[color=blue][color=green][color=darkred]
        >> > and e.Item.Cells[0].ToString()
        >> > returns "System.Web.UI. WebControls.Tab leCell"]
        >> >
        >> > private void DataGrid1_ItemC ommand(object source,
        >> > System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
        >> > {
        >> > if (e.CommandName == "Select1")
        >> > Label1.Text = e.Item.Cells[0].Text; // returns[/color][/color][/color]
        nothing[color=blue][color=green][color=darkred]
        >> > //Label1.Text = "LEFT";
        >> > }
        >> > else
        >> > { {
        >> > Label1.Text = e.Item.Cells[1].Text; // returns[/color][/color][/color]
        nothing[color=blue][color=green][color=darkred]
        >> > //Label1.Text = "RIGHT";
        >> > }
        >> > }
        >> >
        >> > How can I see the data contents of an individual cell[/color][/color][/color]
        of[color=blue][color=green][color=darkred]
        >> > the DataGrid?[/color]
        >>
        >>[/color]
        >
        >
        >.
        >[/color]

        Comment

        Working...