GridView and a button (asp.net2)

Discussion in 'ASP .Net' started by =?Utf-8?B?cGVsZWdrMQ==?=, Jul 29, 2007.

  1. 1)how do i add a button to a grid view (in a column of its own)?
    2)how do i change the text that appeaers on the button RowCreated Event ?
    3)with which event can i change the text on the button when the button is
    pressed and how?
    thnaks i nadvance
    peleg
    =?Utf-8?B?cGVsZWdrMQ==?=, Jul 29, 2007
    #1
    1. Advertising

  2. "pelegk1" <> wrote in message
    news:D...

    > 1)how do i add a button to a grid view (in a column of its own)?


    <asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="False"
    OnRowDataBound="MyGridView_RowDataBound">
    <Columns>
    <asp:TemplateField HeaderText="Select">
    <ItemTemplate>
    <asp:Button ID="MyButton" runat="server">
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>


    > 2)how do i change the text that appeaers on the button RowCreated Event ?


    protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
    e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    ((Button)e.Row.FindControl("MyButton")).Text = "Hello";
    }
    }


    > 3)with which event can i change the text on the button when the button is
    > pressed and how?


    protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
    e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    ((Button)e.Row.FindControl("MyButton")).Attributes.Add("onclick",
    "this.value='Clicked';");
    }
    }


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
    Mark Rae [MVP], Jul 29, 2007
    #2
    1. Advertising

  3. thnaks alot!

    "Mark Rae [MVP]" wrote:

    > "pelegk1" <> wrote in message
    > news:D...
    >
    > > 1)how do i add a button to a grid view (in a column of its own)?

    >
    > <asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="False"
    > OnRowDataBound="MyGridView_RowDataBound">
    > <Columns>
    > <asp:TemplateField HeaderText="Select">
    > <ItemTemplate>
    > <asp:Button ID="MyButton" runat="server">
    > </ItemTemplate>
    > </asp:TemplateField>
    > </Columns>
    > </asp:GridView>
    >
    >
    > > 2)how do i change the text that appeaers on the button RowCreated Event ?

    >
    > protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
    > e)
    > {
    > if (e.Row.RowType == DataControlRowType.DataRow)
    > {
    > ((Button)e.Row.FindControl("MyButton")).Text = "Hello";
    > }
    > }
    >
    >
    > > 3)with which event can i change the text on the button when the button is
    > > pressed and how?

    >
    > protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
    > e)
    > {
    > if (e.Row.RowType == DataControlRowType.DataRow)
    > {
    > ((Button)e.Row.FindControl("MyButton")).Attributes.Add("onclick",
    > "this.value='Clicked';");
    > }
    > }
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    =?Utf-8?B?cGVsZWdrMQ==?=, Jul 30, 2007
    #3
  4. abou the thirds Question:
    how can i add a sub that wil get the click event
    and get the data from : (something like:)

    CType(e.Row.DataItem, Data.DataRowView)("isActive").ToString

    thnaks in advance
    peleg
    "Mark Rae [MVP]" wrote:

    > "pelegk1" <> wrote in message
    > news:D...
    >
    > > 1)how do i add a button to a grid view (in a column of its own)?

    >
    > <asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="False"
    > OnRowDataBound="MyGridView_RowDataBound">
    > <Columns>
    > <asp:TemplateField HeaderText="Select">
    > <ItemTemplate>
    > <asp:Button ID="MyButton" runat="server">
    > </ItemTemplate>
    > </asp:TemplateField>
    > </Columns>
    > </asp:GridView>
    >
    >
    > > 2)how do i change the text that appeaers on the button RowCreated Event ?

    >
    > protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
    > e)
    > {
    > if (e.Row.RowType == DataControlRowType.DataRow)
    > {
    > ((Button)e.Row.FindControl("MyButton")).Text = "Hello";
    > }
    > }
    >
    >
    > > 3)with which event can i change the text on the button when the button is
    > > pressed and how?

    >
    > protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
    > e)
    > {
    > if (e.Row.RowType == DataControlRowType.DataRow)
    > {
    > ((Button)e.Row.FindControl("MyButton")).Attributes.Add("onclick",
    > "this.value='Clicked';");
    > }
    > }
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net
    >
    >
    =?Utf-8?B?cGVsZWdrMQ==?=, Jul 30, 2007
    #4
    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. Anders S. Willumsen

    Partial class and code behind in asp.net2

    Anders S. Willumsen, Jul 31, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    2,004
    Scott Allen
    Aug 1, 2005
  2. bb
    Replies:
    2
    Views:
    373
  3. =?Utf-8?B?QWJoaWplZXQgS3VtYXI=?=

    Freeze columns in GridView ASP.NET2.0(Urgent)

    =?Utf-8?B?QWJoaWplZXQgS3VtYXI=?=, Jun 28, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    28,760
  4. ken
    Replies:
    1
    Views:
    1,552
    Manish
    Apr 17, 2008
  5. Jeremie Legault

    ASP.NET Page ASP.NET2.0

    Jeremie Legault, Nov 23, 2005, in forum: ASP General
    Replies:
    0
    Views:
    131
    Jeremie Legault
    Nov 23, 2005
Loading...

Share This Page