I tried add values to datatable below code.But it just add only ones ,and the same value.I need to add values from parameter.
public DataTable create_table ( string a)
{
DataTable dt = new DataTable();
dt.Columns.Add("Fields",typeof(String));
dt.Rows.Add(new object[] { a });
return dt;
}
thanks in advance.

Jignesh TrivediRank #16 · 50.3K reputationPosted Mar 19, 2013, 7:41 PM EDT
I can not get your question.
can you please provide more info?
Vishal GilbileRank #268 · 9.4K reputationPosted Mar 19, 2013, 8:18 PM EDT
For adding a new row in your DataTable you need to create an instance of DataRow class by using dt.NewRow() function of your datatable. For Eg the following line of code will provide you an idea for the same.
DataRow dr=dt.NewRow();
dr[0]=a;
Hope that Solves your problem.
With Regards,
Vishal Gilbile
Posted Mar 19, 2013, 9:59 PM EDT
Posted Mar 19, 2013, 10:00 PM EDT
Sreejesh SPRank #1,975 · 740 reputationPosted Mar 19, 2013, 10:33 PM EDT
please use viewstate and solve your problem,
Example
protected void page_load(object sender,Eventargs e)
{
if(!ispostback)
{
viewstate["data"]=null;
}
}
public DataTable create_table ( string a)
{
DataTable dt = new DataTable();
if(viewstate["data"]!=null)
{
dt=(datatable)viewstate["data"];
}
dt.Columns.Add("Fields",typeof(String));
dt.Rows.Add(new object[] { a });
viewstate["data"]=dt;
return dt;
}
Please try this Code
thanks
sreejesh