Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GridView and a button (asp.net2)

Reply
Thread Tools

GridView and a button (asp.net2)

 
 
=?Utf-8?B?cGVsZWdrMQ==?=
Guest
Posts: n/a
 
      07-29-2007
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
 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      07-29-2007
"pelegk1" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...

> 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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?cGVsZWdrMQ==?=
Guest
Posts: n/a
 
      07-30-2007
thnaks alot!

"Mark Rae [MVP]" wrote:

> "pelegk1" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>
> > 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
>
>

 
Reply With Quote
 
=?Utf-8?B?cGVsZWdrMQ==?=
Guest
Posts: n/a
 
      07-30-2007
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" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>
> > 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
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling browser back button for GridView Paging and Sorting in Ajax1.1 and 3.5 (using Visual Studio 2005/ Visual studio 2008) anil reddy ASP .Net 0 02-11-2009 04:22 PM
drag and drop from gridview to gridview sebastianthegreatful@gmail.com ASP .Net 0 04-16-2008 10:54 AM
gridview and sqldatasource - refresh the gridview phil ASP .Net 2 11-14-2006 06:09 AM
How to fire both event button click and textchanged when button is click and text is changed Amy ASP .Net 0 06-01-2006 02:33 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM



Advertisments