473,788 Members | 2,868 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y adding a column of Checkboxes to Gridview

Hi,

Could someone please help me with sample code on how to
programmaticall y add a column of checkboxes to data displayed in a
Gridview? And how to find whether the checkbox is checked or not on
postback.

Thanks in advance.
Jun 27 '08 #1
3 6288
hi and hello good day.

you can try this codes:

//declare it to the top
DataGridViewChe ckBoxColumn mygrid = new DataGridViewChe ckBoxColumn();

private void Form1_Load(obje ct sender, EventArgs e)
{
mygrid.HeaderTe xt = "Status";
mygrid.Name = "status";
grid.Columns.In sert(0, mygrid);
}

private void grid_CellMouseC lick(object sender,
DataGridViewCel lMouseEventArgs e)
{
if (mygrid.ThreeSt ate == false)
{MessageBox.Sho w("check");}
else
{MessageBox.Sho w("uncheck"); }
}

I hope it can help u

--
To be Happy is To be Yourself
"d.***********@ gmail.com" wrote:
Hi,

Could someone please help me with sample code on how to
programmaticall y add a column of checkboxes to data displayed in a
Gridview? And how to find whether the checkbox is checked or not on
postback.

Thanks in advance.
Jun 27 '08 #2
On Apr 28, 10:50*pm, d.s.steven...@g mail.com wrote:
Hi,

Could someone please help me with sample code on how to
programmaticall y add a column of checkboxes to data displayed in a
Gridview? And how to find whether the checkbox is checked or not on
postback.

Thanks in advance.
Hi,

Take a look at ITemplate
Jun 27 '08 #3
Thanks for your help.. I get the following error when i try the code
you supplied.

cannot convert from 'System.Windows .Forms.DataGrid ViewCheckBoxCol umn'
to System.Web.UI.W ebControls.Data ControlField'

code:

DataGridViewChe ckBoxColumn mygrid = new DataGridViewChe ckBoxColumn();
mygrid.HeaderTe xt = "Status";
mygrid.Name = "status";
grdAdv.Columns. Insert(0, mygrid); //Error produced on this line.

Any ideas?
Jun 27 '08 #4

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

Similar topics

1
2222
by: | last post by:
I'm wondering if it's possible, outside of the declaration of an ASP.NET 2.0 GridView, to programmatically style individual columns. For example, I might want to make the text in a particular column bold, or larger. I know that Templates and other declarative mechanisms exist to make this happen. I'm wondering if you can apply the styling using code only. What is the general syntax? Flash Actionscript has this "after the fact"...
0
1044
by: Jaime Stuardo | last post by:
Hi all... I have the following curious problem, I have a GridView that I bind after I press a button in the web form. That grid has a template column, which contains a checkbox (in the header and in each row). The grid view is configured to be sortable. These are the event handlers that causes the post back (click for the button and when the grid has to be sorted)
2
6735
by: Wayne Deleer | last post by:
Hi All, I'm currently working on a project, and I've come to a part where I want to add data to a GridView. BUT, I want to do it programmatically, with alot of control over everything. In my particular project I've passed a DataSet to a page via a Session object. The Session object passes without incident, and I can use the default settings to retrieve the information without problem and plug all the information into the GridView.
0
2188
by: GMartin | last post by:
I have a pop-up form with a three columned Grid that has checkboxes in a Template Column in the first/left-most column. (The form is to allow users to select "Members" of a group, where they check or clear the boxes next to the potential members they want to add or remove.) The Object Data Source is as follows... <asp:ObjectDataSource ID="odsMembers" runat="server" SelectMethod="GetGroupMembersSelectList"...
5
23635
by: NKaufman | last post by:
<asp:GridView ID="Basic" runat="server" DataKeyNames="QuestionID,isHeading" AutoGenerateColumns="false" AllowPaging="true" PageSize="100"> <Columns> <asp:BoundField Visible="false" DataField="QuestionID" HeaderText="QuestionID"></asp:BoundField> <asp:BoundField DataField="QuestionDesc" HeaderText="Question" ItemStyle-HorizontalAlign="Left"></ asp:BoundField>
0
5026
by: =?Utf-8?B?SlA=?= | last post by:
I have several data sources that use the same gridView. I need to remove columns from the gridview at run time where the DataBind.Eval statements dont apply to the query currently using the grid. I have discovered that using gridView.Columns.Remove(...) causes the gridView OnRowCommand to quit functioning for any columns that remain in the grid. (MS Please look into this, obviously a bug). So Ive been looking at other ways to hide the...
3
9009
by: =?Utf-8?B?Um9iZXJ0IFNtaXRo?= | last post by:
Hi, I have a GridView with a checkbox column in it called FromInsight, however this is not bound to the dataset, its value is based on another column from the dataset called sourceid For each row FromInsight = true if (SourceId 0). I try to loop around the gridview and add the value of the checkbox but the column seems to have no checked value, please can you help with this. Thanx in advance Robert
3
2761
by: santoshjsh | last post by:
hello everyone, i have a gridview in which i have multiple checkboxes in a single column. means for every row in the gridview i have four checkboxes in one column e.g Add, Delete, Print, Modify. now i need to bind these check boxes from database table according to the four different fields in the table in which the value is 0 and 1. if the column value is 1 than the checkbox should be displayed checked otherwise no. i dont know how...
2
6395
by: John Straumann | last post by:
Hello all: I am trying to populate a GridView with data being read from a call to a web service. I have seen plenty of examples that simply execute a SQL data reader, set the Grid data source to the reader, and then call DataBind(), but I cannot seem to figure out how to build the GridView row by row with anything except text. I need the 2nd column of the Grid to be a hyperlink or a button, and this is where I am having an issue. I can...
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10366
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10175
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10112
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4070
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.