473,396 Members | 1,826 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,396 software developers and data experts.

CheckBoxList inside a DataGrid.

I can't seem to figure out why I am unable to populate a checkboxlist
inside a Datagrid.

I have a DataSet with a DataTable called ServerInfo. The Datatable has
two columns. MapName and PlayerName.

I have a Datagrid control with a checkboxlist control as an
itemtemplate.

I bind the DataSet to the DataGrid and the info shows up in the grid.
How do i bind the MapName column to a checkboxlist inside the datagrid.

Thanks in advance

KC

Here is a sample:

CodeBehind Page
----------------------------------------------------------------
DataSet ds = new DataSet();
DataTable dt = new DataTable("ServerInfo");
DataColumn dtCol;
DataRow dtRow;
dtCol = new DataColumn();
dtCol.ColumnName = "MapName";
dtCol.DataType = Type.GetType("System.String");
dt.Columns.Add(dtCol);
dtCol = new DataColumn();
dtCol.ColumnName = "PlayerName";
dtCol.DataType = Type.GetType("System.String");
dt.Columns.Add(dtCol);
ArrayList arServerData = new ArrayList();
ArrayList arPlayerData = new ArrayList();
arServerData.Add("Map1");
arServerData.Add("Map2");
arServerData.Add("Map3");
foreach(item mapname in arServerData)
{
dtCol["MapName"] = mapname;
}
arPlayerData.Add("Player1");
arPlayerData.Add("Player2");
arPlayerData.Add("Player3");
foreach(item playername in arPlayerData)
{
dtCol["PlayerName"] = arPlayerData;
}
ds.Tables.Add(dt);

DataGrid2.DataSource = ds.Tables["ServerInfo"].DefaultView;
DataGrid2.DataBind();
asp.net Page
----------------------------------------------------------------
<asp:datagrid id="DataGrid2" runat="server" CssClass="ListBox"
AutoGenerateColumns="False"> <Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="CheckBoxMapName" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn> <asp:TemplateColumn> <ItemTemplate>
<asp:CheckBoxList id="CheckBoxList1" runat="server" ForeColor="White"
DataTextField='<%# DataBinder.Eval(Container.DataItem, "MapName" ) %>'
</asp:CheckBoxList>

</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Nov 17 '05 #1
1 2436
have look at http://www.datagridgirl.com/articles.aspx
Himanshu

Nov 17 '05 #2

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

Similar topics

1
by: Mats | last post by:
Hi I am working on a webapplication using Asp.net with C#. I have Datagrid that have 3 colums two of them are text but the last one is a CheckBoxList. I have manage to set data to the...
3
by: Egbert | last post by:
I use a System.Web.UI.WebControls.CheckBoxList object to fill a list. I need to label groups of checkboxes in the list by Category (Determined dynamically from the database) at runtime. Is it...
0
by: Francois Verbeeck | last post by:
Dear UseNet readers, Does anyone have any idea on how to colorize selected checkbox in checkboxlist control ? I've quite a huge checkboxlist (approximatively one full screen) and, to improve...
3
by: JD | last post by:
Hello, I have a problem with checkboxlist inside Repeater (in ASP.NET page). I am able to create Checkboxlist and bind it (inside Repeater_ItemBound - including setting checked/unchecked)....
4
by: Patrick.O.Ige | last post by:
I have a CheckBoxList in a DataList and i'm trying to get item Selected after doing a postBack. I have set my CheckBoxlist AutoPostBack="True" Any ideas what 'm doing wrong? It seems not to...
0
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView...
0
by: Jai | last post by:
Hi, Somebody please tell me how to bind(two way) a checkboxlist with objectdatasource if the checkboxlist is inside a formview..... Code of FormView is like this::--- <asp:FormView...
6
by: dbuchanan | last post by:
There are three parts to this 1.) How do I cascade menus? 2.) And, how do I cascade menus with a multi-select CheckBoxList?
0
by: =?Utf-8?B?U2F2dm91bGlkaXMgSW9yZGFuaXM=?= | last post by:
In VS2008, I have a DetailsView control with a checkboxlist control inside its Edit template. (1) I want the checkboxlist to be dynamic and display only as many checkboxes as a user setting is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
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...
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.