GridView and a button (asp.net2)

G

Guest

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
 
M

Mark Rae [MVP]

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>
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';");
}
}
 
G

Guest

thnaks alot!

Mark Rae said:
<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>


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



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';");
}
}
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top