GridView Questions

Discussion in 'ASP .Net' started by =?Utf-8?B?Q2hyaXMgRGF2b2xp?=, Aug 5, 2006.

  1. I've got two questions on how to do things in the new GridView. I'm used to
    the DataGrid in ASP 1.1, so I need the equavalent in ASP 2.0 Gridview.

    1.) What is the equavalent for Item Command event in GridView? I thought it
    would be RowCommand, but I can't get that event to fire with a check box
    field that I drag/drop in a template column in the ItemTemplate.

    2.) For a Templated column, like a check box above, where do I tell it the
    data field to bind from the data source? There is not a Template DataField
    property to set to the database field name as in a bound field.


    --
    Chris Davoli
     
    =?Utf-8?B?Q2hyaXMgRGF2b2xp?=, Aug 5, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?Q2hyaXMgRGF2b2xp?=

    Teemu Keiski Guest

    Hi,

    first of all, DataGrid still exists in ASP.NET 2.0, so you can use it also.
    But the replies:

    1) RowCommand is the equivalent. CheckBox doesn't raise ItemCommand event
    since it doesn't provide CommandName and CommandArgument
    attributes/properties to apply event bubbling which raising
    ItemCommand/RowCommand basically is (it doesn't raise it in ASP.NET v1.1
    either). By default only Button, ImageButton or ImageButton (=IButtonControl
    interface) or the built-in command columns/fields also raise correspondiong
    event in GridView. Can you show an exa,ple what you want to do,.or how you
    have done it in v1.1?

    2) You would use a databinding expression as in v1.1. For example
    <%#Eval("FieldName") %> within <ItemTemplate>...</ItemTemplate>. Tenplate
    field is templated and setting the layout etc is in developer's hands so
    having datafield for it wouldn't make sense.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    "Chris Davoli" <> wrote in message
    news:...
    > I've got two questions on how to do things in the new GridView. I'm used
    > to
    > the DataGrid in ASP 1.1, so I need the equavalent in ASP 2.0 Gridview.
    >
    > 1.) What is the equavalent for Item Command event in GridView? I thought
    > it
    > would be RowCommand, but I can't get that event to fire with a check box
    > field that I drag/drop in a template column in the ItemTemplate.
    >
    > 2.) For a Templated column, like a check box above, where do I tell it the
    > data field to bind from the data source? There is not a Template DataField
    > property to set to the database field name as in a bound field.
    >
    >
    > --
    > Chris Davoli
    >
     
    Teemu Keiski, Aug 5, 2006
    #2
    1. Advertising

  3. Hello Chris,
    The equavalent of ItemCommand in GridView is RowCommand.
    What I understood from your question part (1) is you added a checkbox to a
    templated field in your GridView, and you set AutoPostBack to true and
    implemented RowCommand event, and when executing the event is not firing?!
    Well this will not work also in DataGrid. So you can impelement selectChange
    Event of your CheckBox Instead. Hope I hit your idea in this.

    About the second part,
    You want to bind a DataSource Field to your CheckBox located in your
    GridView Templated Field, Well, Select your CheckBox and note the smart tag
    icon in the top right. click on it and you will get Edit DataBindings link.
    click on too and start do what you want.

    Regards,
    --
    Muhammad Mosa
    Software Engineer & Solution Developer
    MCT/MCSD.NET
    MCTS: .Net 2.0 Web Applications
    MCTS: .Net 2.0 Windows Applications


    "Chris Davoli" wrote:

    > I've got two questions on how to do things in the new GridView. I'm used to
    > the DataGrid in ASP 1.1, so I need the equavalent in ASP 2.0 Gridview.
    >
    > 1.) What is the equavalent for Item Command event in GridView? I thought it
    > would be RowCommand, but I can't get that event to fire with a check box
    > field that I drag/drop in a template column in the ItemTemplate.
    >
    > 2.) For a Templated column, like a check box above, where do I tell it the
    > data field to bind from the data source? There is not a Template DataField
    > property to set to the database field name as in a bound field.
    >
    >
    > --
    > Chris Davoli
    >
     
    =?Utf-8?B?TXVoYW1tYWQgTW9zYQ==?=, Aug 5, 2006
    #3
  4. Thanks for the ideas. They may help, but here is more of what I need.

    For #1:
    If I use the selectChange event to check the check box, how do I tell which
    row the check box was checked (multiple rows in the gridview)? Also, how do I
    get say another field ie a unique Index to be used for DB calls etc.?

    For #2:
    I found the smart tag(Edit Data bIndings), but it is not enabled. Binding
    for Checked fields below it are all disabled. I see the fields, but they are
    disabled. Only the custom binding is enabled. How do I enable the bindings?
    --
    Chris Davoli



    "Muhammad Mosa" wrote:

    > Hello Chris
    > The equavalent of ItemCommand in GridView is RowCommand.
    > What I understood from your question part (1) is you added a checkbox to a
    > templated field in your GridView, and you set AutoPostBack to true and
    > implemented RowCommand event, and when executing the event is not firing?!
    > Well this will not work also in DataGrid. So you can impelement selectChange
    > Event of your CheckBox Instead. Hope I hit your idea in this.
    >
    > About the second part,
    > You want to bind a DataSource Field to your CheckBox located in your
    > GridView Templated Field, Well, Select your CheckBox and note the smart tag
    > icon in the top right. click on it and you will get Edit DataBindings link.
    > click on too and start do what you want.
    >
    > Regards,
    > --
    > Muhammad Mosa
    > Software Engineer & Solution Developer
    > MCT/MCSD.NET
    > MCTS: .Net 2.0 Web Applications
    > MCTS: .Net 2.0 Windows Applications
    >
    >
    > "Chris Davoli" wrote:
    >
    > > I've got two questions on how to do things in the new GridView. I'm used to
    > > the DataGrid in ASP 1.1, so I need the equavalent in ASP 2.0 Gridview.
    > >
    > > 1.) What is the equavalent for Item Command event in GridView? I thought it
    > > would be RowCommand, but I can't get that event to fire with a check box
    > > field that I drag/drop in a template column in the ItemTemplate.
    > >
    > > 2.) For a Templated column, like a check box above, where do I tell it the
    > > data field to bind from the data source? There is not a Template DataField
    > > property to set to the database field name as in a bound field.
    > >
    > >
    > > --
    > > Chris Davoli
    > >
     
    =?Utf-8?B?Q2hyaXMgRGF2b2xp?=, Aug 6, 2006
    #4
  5. For #1:
    a)Implement RowDataBound of your GridView as the following:
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    DataRowView row = (DataRowView)e.Row.DataItem;
    CheckBox chk = (CheckBox)e.Row.FindControl("CheckBox1");
    chk.Attributes["CustomValue"] = row["ProductID"].ToString();
    }
    }
    Note that I have added CustomValue attribute to everu check box with datakey
    value stored in it.
    b)Now Implement selectChanged event of your checkbox but don't forget to set
    autopostback to true
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
    string s = ((CheckBox)sender).Attributes["CustomValue"];
    }

    For #2
    in the custom binding area, add Eval("YourDataFieldName") or
    Bind("YourDataFieldName")

    Hope this would help
    --
    Muhammad Mosa
    Software Engineer & Solution Developer
    MCT/MCSD.NET
    MCTS: .Net 2.0 Web Applications
    MCTS: .Net 2.0 Windows Applications
     
    =?Utf-8?B?TXVoYW1tYWQgTW9zYQ==?=, Aug 6, 2006
    #5
    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. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    18,024
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  2. Ali Syed
    Replies:
    3
    Views:
    578
    Mark McIntyre
    Oct 13, 2004
  3. pkirk25
    Replies:
    50
    Views:
    1,160
    Bill Pursell
    Oct 4, 2006
  4. Replies:
    10
    Views:
    571
  5. Vijay
    Replies:
    2
    Views:
    629
    Öö Tiib
    May 7, 2010
Loading...

Share This Page