Hi Vidya please follow the following snippet I have created for you hope you will get a proper solution
Name Spaces Used
using System.Data;
C# Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add("EmpID");
dt.Columns.Add("Name");
dt.Rows.Add("1", "Rk_Hirpara");
dt.Rows.Add("2", "Mudassar");
dt.Rows.Add("3", "Ashutosh");
dt.Rows.Add("4", "Adnaan");
chkEmployee.DataSource = dt;
chkEmployee.DataTextField = "Name";
chkEmployee.DataValueField = "EmpID";
chkEmployee.DataBind();
}
//GenerateXML(dt);
}
private void GenerateXML(DataTable tbl)
{
DataSet ds = new DataSet();
ds.Tables.Add(tbl);
ds.WriteXml(@"C:\Test\Test.xml");
}
protected void Ok_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("EmpID");
dt.Columns.Add("Name");
foreach (ListItem item in chkEmployee.Items)
{
if (item.Selected)
{
dt.Rows.Add(item.Value, item.Text);
}
}
GenerateXML(dt);
}
Html
<div>
<asp:CheckBoxList ID="chkEmployee" runat="server"></asp:CheckBoxList>
<asp:Button ID="Ok" runat="server" Text="Ok" onclick="Ok_Click" />
</div>
Thanks and Regards,
Rk_Hirpara.