473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I add a buttonfield to my gridview?

I have a grid view that I have formatted using table objects (see
below). But now I want to add a buttonfield within <tdtags, it will
not let me. How do I add a buttonfield?

<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" ShowHeader="false"
BackColor="#dddddd" DataKeyNames="ProjectID,TaskID"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table width="450">
<tr>
<td width="100px">
<asp:label
id="lblProjectName" Runat="server" Font-Bold="true" BackColor="Red"
ForeColor="White">PROJECT NAME</asp:label>
</td>
<td width="300px" align=left>
<asp:Label
ID="lblProjectName2" runat="server" Text='<%# Bind("ProjectName") %>'
Font-Bold="true" BackColor="red" ForeColor="White"></asp:Label>
</td>
</tr>
<tr>
<td width="100px">
<asp:label
id="lblProjectAssignedTo" Runat="server">Assigned To</asp:label>
</td>
<td width="300px" align=left>
<asp:Label
ID="lblProjectAssignedTo2" runat="server" Text='<%#
Bind("ProjectAssignedToName") %>'></asp:Label>
</td>
</tr>
<tr>
<td width="100px">
<asp:label
id="lblProjectStartDate" Runat="server">Start Date/Time</asp:label>
</td>
<td width="300px" align=left>
<asp:Label
ID="lblProjectStartDate2" runat="server" Text='<%#
Bind("ProjectStartDate") %>'></asp:Label>
</td>
</tr>
<tr>
<td width="100px">
<asp:label
id="lblProjectEndDate" Runat="server">End Date/Time</asp:label>
</td>
<td width="300px" align=left>
<asp:Label
ID="lblProjectEndDate2" runat="server" Text='<%# Bind("ProjectEndDate")
%>'></asp:Label>
</td>
</tr>
<tr>
<td>
//trying to add a button
field here
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #1
4 1571
Hi

i add a button and worked okay for me...

<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" ShowHeader="false"
BackColor="#dddddd" DataKeyNames="ProjectID,TaskID"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table width="450">
<tr>
<td width="100px">
<asp:Label ID="lblProjectName"
runat="server" Font-Bold="true" BackColor="Red"
ForeColor="White">PROJECT NAME</asp:Label>
</td>
<td width="300px" align="left">
<asp:Label ID="lblProjectName2"
runat="server" Text='<%# Bind("ProjectName") %>'
Font-Bold="true" BackColor="red"
ForeColor="White"></asp:Label>
</td>
</tr>
<tr>
<td width="100px">
<asp:Label ID="lblProjectAssignedTo"
runat="server">Assigned To</asp:Label>
</td>
<td width="300px" align="left">
<asp:Label ID="lblProjectAssignedTo2"
runat="server" Text='<%# Bind("ProjectAssignedToName") %>'></
asp:Label>
</td>
</tr>
<tr>
<td width="100px">
<asp:Label ID="lblProjectStartDate"
runat="server">Start Date/Time</asp:Label>
</td>
<td width="300px" align="left">
<asp:Label ID="lblProjectStartDate2"
runat="server" Text='<%# Bind("ProjectStartDate") %>'></asp:Label>
</td>
</tr>
<tr>
<td width="100px">
<asp:Label ID="lblProjectEndDate"
runat="server">End Date/Time</asp:Label>
</td>
<td width="300px" align="left">
<asp:Label ID="lblProjectEndDate2"
runat="server" Text='<%# Bind("ProjectEndDate")%>'></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Button runat="server"
ID="mydesiredButton" Text="DesiredButton" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
Jun 27 '08 #2
Hi

Give the button a command name

<asp:Button ID="somebutton" runat="server" Text="Abutton"
CommandName="myCommandName" />

subscript the itemcommand event of the datagrid or gridview

and on item command

protected void ListView1_ItemCommand(object sender,
ListViewCommandEventArgs e)
{
if (e.CommandName == "myCommandName")
{
//put your code here
}

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
}
Jun 27 '08 #3
Thanks, but I still get the same error. Any ideas?

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #4
Hi,

Are u using asp.net ajax update panel ?

follow this thread , might help you

http://forums.asp.net/p/922994/1064482.aspx

Best of luck

Munna

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Edwin Knoppert | last post by:
I post this again, no answer before. During the beta version it worked, the same code does no longer work in the new release. I have a simple gridview with ButtonField, the button deletes a...
0
by: nx-2000 | last post by:
ASP.Net 2.0. I've got a GridView, its got a DataKeyNames set to the ID of the item that's in a row. I added a ButtonField column, made it a Button type with my "Remove" text, and when I hit the...
1
by: lanem | last post by:
I have a gridview. One of the columns is a buttonfield. I use the datatextfield property of buttonfield to show my bound value as a hyperlink in each buttonfield cell. I then want to get that...
3
by: jhaidon | last post by:
Hi everybody, I want to fill in a GridView with a dataset. So I created the list of fields that I want to see in the gridview. And I added a column (in first position in the gridview) as a...
1
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I am using ASP.Net 2.0 themes, and have a GridView with a ButtonField column. I can not find a way to create a style for ButtonField columns in the application's theme, specifically, I want to set...
3
by: GaryDean | last post by:
I have a button field in a gridview defined as follows: <asp:ButtonField ButtonType="Button" CommandName="AcceptOrder" Text="Accept Whole Order"> <ControlStyle Font-Size="X-Small" />...
3
by: pbd22 | last post by:
Hi. How do I add the runat=server attribute on a buttonfield link dynamically? thanks!
1
by: Elmo Watson | last post by:
I know how to add a confirmation or an AJAX extender to a regular button, but is there any way to add a confirm (yes/no) to a ButtonField in a Gridview?
2
by: Elmo Watson | last post by:
I've converted a buttonfield to a TemplateField with a button in it Previously, in the Rowcommand, to identify the row when the ButtonField was clicked, I had this code: Dim index As Integer =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.