Datagrid columns

Discussion in 'ASP .Net Web Controls' started by Darin, Oct 21, 2003.

  1. Darin

    Darin Guest

    I posted this question in the ASP.NET newsgroup not
    knowing about this newsgroup.

    I need to create a column with 4 links in that column
    that take 4 different actions against that row when
    clicked.

    I do not see how to add 4 links under one column using
    the datagrid's property builder.

    Can anyone give me any direction or links to articles?

    Thanks.
    ..
     
    Darin, Oct 21, 2003
    #1
    1. Advertising

  2. Darin

    Oliver Guest

    Hi Darin,

    You want to create a template column, put your button items in it and set the
    CommandName property for each. Then in your code, you catch the ItemCommand
    event and evaluate which object cause the event. The .aspx stuff is first
    below, then the event handler code.

    <columns>
    <asp:templatecolumn>
    <itemtemplate>
    <p>
    <asp:linkbutton id="LinkButton1" runat="server"
    causesvalidation="false" commandname="Navigate"
    text="MultiAction" tooltip="Goes elsewhere">Navigate
    Away</asp:linkbutton></p>
    <p>
    <asp:button id="Button1" runat="server" commandname="ShowTime"
    text="Show Time"></asp:button></p>
    <p>
    <asp:imagebutton id="ImageButton1" runat="server"
    commandname="MakeRed"
    imageurl="http://www.gc.ca/images/flag.gif"></asp:imagebutton></p>
    <p>
    <asp:linkbutton id="LinkButton2" runat="server"
    commandname="Update" borderstyle="Solid"
    bordercolor="#FFFFC0">Update</asp:linkbutton></p>
    </itemtemplate>
    </asp:templatecolumn>
    <asp:boundcolumn datafield="UnitPrice"
    dataformatstring="{0:C}"></asp:boundcolumn>
    </columns>


    Private Sub DataGrid1_ItemCommand _
    (ByVal source As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles DataGrid1.ItemCommand
    Select Case e.CommandName
    Case "Navigate"
    Response.Redirect("http://www.aspalliance.com/kenc")
    Case "ShowTime"
    Label1.Text = Now.ToLongTimeString
    Case "Update"
    Response.Write("<script>alert('This would update')</script>")

    Case "MakeRed"
    e.Item.BackColor = Color.Red
    End Select
    End Sub

    "Darin" <> wrote in message
    news:02a701c39814$cf9e1ec0$...
    I posted this question in the ASP.NET newsgroup not
    knowing about this newsgroup.

    I need to create a column with 4 links in that column
    that take 4 different actions against that row when
    clicked.

    I do not see how to add 4 links under one column using
    the datagrid's property builder.

    Can anyone give me any direction or links to articles?

    Thanks.
    ..
     
    Oliver, Oct 22, 2003
    #2
    1. Advertising

  3. Darin

    darin Guest

    Thanks Oliver!


    >-----Original Message-----
    >Hi Darin,
    >
    >You want to create a template column, put your button

    items in it and set the
    >CommandName property for each. Then in your code, you

    catch the ItemCommand
    >event and evaluate which object cause the event.

    The .aspx stuff is first
    >below, then the event handler code.
    >
    > <columns>
    > <asp:templatecolumn>
    > <itemtemplate>
    > <p>
    > <asp:linkbutton id="LinkButton1"

    runat="server"
    >causesvalidation="false" commandname="Navigate"
    > text="MultiAction" tooltip="Goes

    elsewhere">Navigate
    >Away</asp:linkbutton></p>
    > <p>
    > <asp:button id="Button1" runat="server"

    commandname="ShowTime"
    >text="Show Time"></asp:button></p>
    > <p>
    > <asp:imagebutton id="ImageButton1"

    runat="server"
    >commandname="MakeRed"
    >imageurl="http://www.gc.ca/images/flag.gif"></asp:imagebu

    tton></p>
    > <p>
    > <asp:linkbutton id="LinkButton2"

    runat="server"
    >commandname="Update" borderstyle="Solid"
    >bordercolor="#FFFFC0">Update</asp:linkbutton></p>
    > </itemtemplate>
    > </asp:templatecolumn>
    > <asp:boundcolumn datafield="UnitPrice"
    >dataformatstring="{0:C}"></asp:boundcolumn>
    > </columns>
    >
    >
    > Private Sub DataGrid1_ItemCommand _
    > (ByVal source As Object, _
    > ByVal e As

    System.Web.UI.WebControls.DataGridCommandEventArgs) _
    > Handles DataGrid1.ItemCommand
    > Select Case e.CommandName
    > Case "Navigate"
    > Response.Redirect

    ("http://www.aspalliance.com/kenc")
    > Case "ShowTime"
    > Label1.Text = Now.ToLongTimeString
    > Case "Update"
    > Response.Write("<script>alert('This would

    update')</script>")
    >
    > Case "MakeRed"
    > e.Item.BackColor = Color.Red
    > End Select
    > End Sub
    >
    >"Darin" <> wrote in

    message
    >news:02a701c39814$cf9e1ec0$...
    >I posted this question in the ASP.NET newsgroup not
    >knowing about this newsgroup.
    >
    >I need to create a column with 4 links in that column
    >that take 4 different actions against that row when
    >clicked.
    >
    >I do not see how to add 4 links under one column using
    >the datagrid's property builder.
    >
    >Can anyone give me any direction or links to articles?
    >
    >Thanks.
    >..
    >
    >
    >
    >.
    >
     
    darin, Oct 22, 2003
    #3
    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. helpful sql
    Replies:
    0
    Views:
    815
    helpful sql
    May 19, 2005
  2. Replies:
    5
    Views:
    598
  3. Replies:
    4
    Views:
    940
  4. rob thomson
    Replies:
    0
    Views:
    261
    rob thomson
    Sep 4, 2003
  5. ton
    Replies:
    2
    Views:
    206
    Alvin Bruney [MVP]
    Feb 11, 2004
Loading...

Share This Page