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.
Sreejesh SPPosted Mar 20, 2013, 2:33 AM
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
Posted Mar 20, 2013, 2:00 AM
Posted Mar 20, 2013, 1:59 AM
Vishal GilbilePosted Mar 20, 2013, 12:18 AM
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
Jignesh TrivediPosted Mar 19, 2013, 11:41 PM
I can not get your question.
can you please provide more info?