this is my design
onrowdatabound="GridView1_RowDataBound"> onselectedindexchanged="DropDownList1_SelectedIndexChanged"> | ||
code is
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Admin_AddmoreProduct : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=VALUED-HO1E64NO\\SQLEXPRESS;Initial Catalog=Agri;User ID=sa;Password=watt");
REMO sel = new REMO();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
sno();
sg();
}
private void sno()
{
string bill = sel.getmaxid("BillNo", "cement1");
txtbillno.Text = bill.ToString();
}
void LoadData()
{
SqlConnection con = new SqlConnection("Data Source=VALUED-HO1E64NO\\SQLEXPRESS;Initial Catalog=Agri;User ID=sa;Password=watt");
SqlDataAdapter cmd=new SqlDataAdapter("select * from demo",con);
DataSet ds=new DataSet();
cmd.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
private void sg()
{
ListItem sll = new ListItem();
DropDownList3.Items.Add("Cement");
DropDownList3.Items.Add("Seed");
DropDownList3.Items.Add("Pesticide");
DropDownList3.Items.Add("Fetilizer");
DropDownList3.Items.Add(sll.ToString());
}
protected void txtbillno_TextChanged(object sender, EventArgs e)
{
// DataTable dt;
//dt="select
}
// private void prr()
//{
// int s = 0;
// DataSet ds=new DataSet();
// ListItem lim = new ListItem();
// //lim.Text = "Select";
// //lim.Value = "0";
// //DropDownList1.Items.Add(lim.ToString());
// ds = sel.GETDS("select DISTINCT name from demo");
// //DropDownList1.Items.Insert(0, new ListItem("--Select--", "0"));
// foreach (DataRow dr in ds.Tables[0].Rows)
// {
// // DropDownList1.Items.Clear();
// ListItem ss = new ListItem();
// lim.Text = dr["name"].ToString();
// lim.Value = Convert.ToString(s + 1);
// DropDownList1.Items.Add(lim.ToString());
// }
//}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
con.Open();
var ddl = (DropDownList)e.Row.FindControl("ddlw");
//int CountryId = Convert.ToInt32(e.Row.Cells[0].Text);
SqlCommand cmd = new SqlCommand("select weight from demo" , con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddl.DataSource = ds;
ddl.DataTextField = "weight";
//ddl.DataValueField = "StateID";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("--Select--", "0"));
float sllv = Convert.ToInt32((TextBox)GridView1.FindControl("pprice"));
float scv = Convert.ToInt32((DropDownList)GridView1.FindControl("DropDownList1"));
((TextBox)e.Row.FindControl("bfvata")).Text = Convert.ToString(sllv * scv);
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
i need to multiply the value in (requiredno* productprice)=beforevat

Suthish NairPosted Sep 10, 2013, 4:18 AM
Secondly, you must a null check before converting any value.
So change you code...
TextBox txtpprce = (TextBox)e.Row.FindControl("pprce");
if(txtpprce != null)
{
DropDownList ddlDropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1");
if(ddlDropDownList1 != null)
{
TextBox txtbfvata = (TextBox)e.Row.FindControl("bfvata");
if(txtbfvata != null)
{
txtbfvata.Text = Convert.ToString(Convert.ToInt32(txtpprce.Text) * Convert.ToInt32(ddlDropDownList1.SelectedItem.Text));
}
}
}
Jignesh TrivediPosted Sep 10, 2013, 12:11 AM
can please check what is value of (TextBox)e.Row.FindControl("pprce")? when you getting error.
selvi subramanianPosted Sep 9, 2013, 4:10 AM
Jignesh TrivediPosted Sep 9, 2013, 3:49 AM
hi,
This error means...
your text box is not present on the currently accessed row...
Please check your code whether this text box present or not...
selvi subramanianPosted Sep 9, 2013, 3:26 AM
Jignesh TrivediPosted Sep 9, 2013, 3:20 AM
hi,
I am not able to find pprice control on your grid code. i think it pprce....
also this multification is row by row so code must....
float sllv = Convert.ToInt32(((TextBox)e.Row.FindControl("pprce")).Text);
float scv = Convert.ToInt32(((DropDownList)e.Row.FindControl("DropDownList1")).SelectValue);
hope this will help you.
selvi subramanianPosted Sep 9, 2013, 3:03 AM
Jignesh TrivediPosted Sep 9, 2013, 2:58 AM
I think, problem you code is, you are trying to convert textbox / dropdown in to int. but actually you must convert textbox / dropdown value into int...
try...
below two line replace with your code.
float sllv = Convert.ToInt32(((TextBox)GridView1.FindControl("pprice")).Text);
float scv = Convert.ToInt32(((DropDownList)GridView1.FindControl("DropDownList1")).SelectValue);
hope this will help you
selvi subramanianPosted Sep 9, 2013, 2:11 AM
Jignesh TrivediPosted Sep 9, 2013, 12:46 AM
your code looks good and also it must work fine..
are you facing any problem with this code?
Anurag SarkarPosted Sep 8, 2013, 2:17 PM