Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

GridView and a button (asp.net2)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
pelegk1 - 29 Jul 2007 23:34 GMT
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
Mark Rae [MVP] - 29 Jul 2007 23:59 GMT
> 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';");
   }
}

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

pelegk1 - 30 Jul 2007 11:36 GMT
thnaks alot!

> > 1)how do i add a button to a grid view (in a column of its own)?
>
[quoted text clipped - 32 lines]
>     }
> }
pelegk1 - 30 Jul 2007 20:32 GMT
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

> > 1)how do i add a button to a grid view (in a column of its own)?
>
[quoted text clipped - 32 lines]
>     }
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.