Hi everyone,
i want to insert selected value of listview to database but this code does not work.please help me.
GroupItemCount="3">
| font-family: Verdana, Arial, Helvetica, sans-serif; color: #BA2323"> |
protected void ListView1_SelectedIndexChanging(object sender, ListViewSelectEventArgs e)
{
ListViewItem item = (ListViewItem)ListView1.Items[e.NewSelectedIndex];
if (Session["username"] == null)
{
Response.Write("???? ???? ????? ???? ???? ?????? ??? ????");
}
else
{
DataSet1 ds = new DataSet1();
DataSet1TableAdapters.tblFactorTableAdapter ta = new DataSet1TableAdapters.tblFactorTableAdapter();
DataSet1TableAdapters.tblOrderTableAdapter t6 = new DataSet1TableAdapters.tblOrderTableAdapter();
DataSet1TableAdapters.tblOrderTableAdapter ta7 = new DataSet1TableAdapters.tblOrderTableAdapter();
ta.FillByUser(ds.tblFactor, Session["username"].ToString(), false);
Label pidlabel = (Label)item.FindControl("lblpid");
int pid = Convert.ToInt32(pidlabel);
Label pricelabel = (Label)item.FindControl("lblprice");
decimal price = Convert.ToDecimal(pricelabel);
TextBox textbx = (TextBox)item.FindControl("txtcount");
int count = Convert.ToInt32(textbx);
// Response.Write("tedad=" + tedad);
decimal finalprice = price * count;
if (ds.tblFactor.Rows.Count > 0)
{
int fid = int.Parse(ds.tblFactor.Rows[0]["fid"].ToString());
ta7.InsertQuery(fid, pid, price, finalprice, count);
}
else
{
PersianCalendar pc = new PersianCalendar();
string tarikh = pc.GetYear(DateTime.Now) + "/" + pc.GetMonth(DateTime.Now) + "/" + pc.GetDayOfMonth(DateTime.Now);
string saat = DateTime.Now.Hour + ":" + DateTime.Now.Minute;
ta.Insert(tarikh, saat, Session["username"].ToString(), false);
ta.FillByUser(ds.tblFactor, Session["username"].ToString(), false);
int fid = int.Parse(ds.tblFactor.Rows[0]["fid"].ToString());
ta7.InsertQuery(fid, pid, price, finalprice, count);
}
}
}
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
mahnaz afPosted Jun 6, 2015, 5:15 AM
Nilesh JadavPosted Jun 6, 2015, 3:54 AM
http://stackoverflow.com/questions/22399751/how-to-move-data-from-listview-and-insert-into-database
mahnaz afPosted Jun 6, 2015, 3:33 AM
Nilesh JadavPosted Jun 6, 2015, 12:46 AM
Try this links might it work :
http://www.dbtutorials.com/advanced/listview-inserting/
http://www.codeproject.com/Questions/118912/listbox-multiple-selected-values
Thank you