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>