问题描述
我必须向用户展示来自DropDownList的文本框和结束日期的startDate在等Asp.net GridView的例子输入的参数中的值。我从用户获得这些值,并将它们添加到一个临时数据表。我加入每一行DatTable在每次添加按钮调用它去罚款的第一行第一时间意味着当我试图进入添加按钮另一行按我将覆盖previous行,表明我只有一排。
下面是我的code:
BusinessLayer.LaunchPortfolioTest objAddParametersToDataTable =新BusinessLayer.LaunchPortfolioTest();
数据表不是Temptable;如果(会话[不是Temptable] == NULL)
{
不是Temptable = objAddParametersToDataTable.TempTableView();
会话[IDcolumn] = 1;
}
其他
{
会话[IDcolumn] = Convert.ToInt16(会话[IDcolumn])+ 1;
不是Temptable =(数据表)会议[不是Temptable];
}
INT ID = Convert.ToInt16(会话[IDcolumn]);
字符串诺姆= Utilities.formatShortDate(Convert.ToDateTime(txtEndDate.Text.ToString()));
串优先= drpPriority.SelectedValue.ToString();
字符串组合code = drpPortfolio code.SelectedValue.ToString();
日期时间的startDate = Convert.ToDateTime(txtStartDate.Text.ToString());
DateTime的结束日期= Convert.ToDateTime(txtEndDate.Text.ToString());
串货币= drpCalculationCurrency.SelectedValue.ToString();
笔者串= lblLoginnedUser.Text.ToString();
时间跨度差= endDate.Date.AddDays(1) - startDate.Date;
//添加参数数据表到:
objAddParametersToDataTable.AddRow(ID,优先级,作者,诺姆,投资组合code,Convert.ToString(的startDate),Convert.ToString(结束日期),货币,不是Temptable);grdViewReport.DataSource =不是Temptable;
grdViewReport.DataBind();Session.Add(不是Temptable,objAddParametersToDataTable.TempTableView());
TempTableView
方法:
公开数据表TempTableView()
{
数据表TempAnalysisTable =新的DataTable();
DataColumn的身份=新的DataColumn(IDcolumn的typeof(INT));
TempAnalysisTable.Columns.Add(身份);
TempAnalysisTable.Columns.Add(优先级,typeof运算(字符串));
TempAnalysisTable.Columns.Add(作者,typeof运算(字符串));
TempAnalysisTable.Columns.Add(名,typeof运算(字符串));
TempAnalysisTable.Columns.Add(「投资组合code,typeof运算(字符串));
TempAnalysisTable.Columns.Add(起始日期,typeof运算(字符串));
TempAnalysisTable.Columns.Add(结束日期,typeof运算(字符串));
TempAnalysisTable.Columns.Add(货币,typeof运算(字符串));
返回TempAnalysisTable;
}
添加
方法code是在这里:
公共无效AddRow(INT ID,字符串的优先级,串作者,字符串名称,字符串组合code,字符串的startDate,字符串结束日期,字符串货币,数据表TempAnalysisTable)
{
TempAnalysisTable.Rows.Add(新的对象[] {ID,优先级,作者,名称,组合code,的startDate,结束日期,货币});
}
我不知道你的情况。但这里是动态添加网格视图不使用数据库的东西。
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(==的IsPostBack假)
{
DataTable的日期=新的DataTable();
date.Columns.Add(列!,typeof运算(字符串));
date.Columns.Add(列2中的typeof(字符串));
会话[DTE] =日期;
}
}保护无效addbutton_Click(对象发件人,ImageClickEventArgs E)
{
数据表日期=(数据表)会议[DTE];
DataRow的博士= date.NewRow();
博士[列1] = TextBox1.Text.Trim(); //你的价值观
博士[列2] = TextBox2.Text.Trim(); //你的价值观
date.Rows.Add(DR);
GridView1.DataSource =日期;
GridView1.DataBind();
}
它可以帮助你在来到这一关。请让我知道你在这种情况下,进一步的查询。
I have to show users entered parameters in Asp.net Gridview example some values from dropdownlist textboxes and startDate EndDate etc . I am getting these values from user and add them to a Temporary dataTable . i am adding each row to DatTable on every add button call it goes fine for first time means for first row when i try to enter another row on Add button Click i overWrites on previous row and shows me only one row.
Here is my code :
BusinessLayer.LaunchPortfolioTest objAddParametersToDataTable = new BusinessLayer.LaunchPortfolioTest();
DataTable TempTable;
if (Session["TempTable"] == null)
{
TempTable = objAddParametersToDataTable.TempTableView();
Session["IDcolumn"] = 1;
}
else
{
Session["IDcolumn"] = Convert.ToInt16(Session["IDcolumn"]) + 1;
TempTable = (DataTable)Session["TempTable"];
}
int ID = Convert.ToInt16(Session["IDcolumn"]);
string nome = Utilities.formatShortDate(Convert.ToDateTime(txtEndDate.Text.ToString()));
string priority = drpPriority.SelectedValue.ToString();
string portfolioCode = drpPortfolioCode.SelectedValue.ToString();
DateTime startDate = Convert.ToDateTime(txtStartDate.Text.ToString());
DateTime endDate = Convert.ToDateTime(txtEndDate.Text.ToString());
string currency = drpCalculationCurrency.SelectedValue.ToString();
string author = lblLoginnedUser.Text.ToString();
TimeSpan Difference = endDate.Date.AddDays(1) - startDate.Date;
//Adding Parameters to DataTable:
objAddParametersToDataTable.AddRow(ID, priority, author, nome, portfolioCode, Convert.ToString(startDate), Convert.ToString(endDate), currency, TempTable);
grdViewReport.DataSource = TempTable;
grdViewReport.DataBind();
Session.Add("TempTable", objAddParametersToDataTable.TempTableView());
TempTableView
method:
public DataTable TempTableView()
{
DataTable TempAnalysisTable = new DataTable();
DataColumn identity = new DataColumn("IDcolumn", typeof(int));
TempAnalysisTable.Columns.Add(identity);
TempAnalysisTable.Columns.Add("Priority", typeof(string));
TempAnalysisTable.Columns.Add("Author", typeof(string));
TempAnalysisTable.Columns.Add("Name", typeof(string));
TempAnalysisTable.Columns.Add("PortfolioCode", typeof(string));
TempAnalysisTable.Columns.Add("StartDate", typeof(string));
TempAnalysisTable.Columns.Add("EndDate", typeof(string));
TempAnalysisTable.Columns.Add("Currency", typeof(string));
return TempAnalysisTable;
}
Add
Method Code IS here:
public void AddRow(int id,string priority, string author, string name, string portfolioCode, string startDate, string endDate, string currency, DataTable TempAnalysisTable)
{
TempAnalysisTable.Rows.Add(new object[] {id, priority, author, name, portfolioCode, startDate, endDate, currency });
}
Am not sure for you scenario. But here is the thing for adding grid view dynamically without using database.
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
{
DataTable date = new DataTable();
date.Columns.Add("Column !", typeof(string));
date.Columns.Add("Column 2", typeof(string));
Session["dte"] = date;
}
}
protected void addbutton_Click(object sender, ImageClickEventArgs e)
{
DataTable date = (DataTable)Session["dte"];
DataRow dr = date.NewRow();
dr["Column 1"] = TextBox1.Text.Trim();// Your Values
dr["Column 2"] = TextBox2.Text.Trim();// Your Values
date.Rows.Add(dr);
GridView1.DataSource = date;
GridView1.DataBind();
}
It may help you to over come this hurdle. Please let me know your further queries in this case.
这篇关于数据表在ASP.Net会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!