CheckBoxList inside a DataGrid.

N

Netmonster

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=' said:
</asp:CheckBoxList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
 

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

Similar Threads

Datagrid error 1
urget!!Datagrid... 1
datagrid 1
Using template columns 1
ASP.NET Datagrid 1
javascript datagrid events inside item template 2
DropDownList DataGrid 1
Text Value in a TextBox inside Datagrid 2

Top