Hi All,
I am trying to make a order with the help of gridview where a dropdown select a item and label show rate of selected item.
and other two text box quantity inserted by user and amount calculated on item quantity and rate.
but when i am trying to bind these then all item and all rates of each item is polpulating in grid view when i am selecting item from dropdown no rate is change when ever i want if user selct other item then rate should be change.
following is my aspx code..
<asp:GridView ID="gridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" OnRowDataBound="gridView1_RowDataBound" PageSize="5">
<Columns>
<asp:TemplateField HeaderText="Product_Name">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataValueField="product_id" DataTextField="product_name" Width="100px" OnSelectedIndexChanged="DropDownList1_SelectedindexChanged"> </asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product_Rate">
<ItemTemplate>
<asp:Label ID="lblRate" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Product_Rate") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox ID="txtQuantity" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Amount">
<ItemTemplate>
<asp:TextBox ID="txtAmount" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
asp.net c# code.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
namespace RadControlsWebApp1
{
public partial class testtttttttttttttttt : System.Web.UI.Page
{
DataTable dt;
DataRow dr;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillgrid();
createdatatable();
}
}
protected void fillgrid()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
SqlCommand cmd = new SqlCommand("select product_name,product_rate from product_detail", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "product_detail");
gridView1.DataSource = ds;
gridView1.DataBind();
}
protected void createdatatable()
{
dt = new DataTable();
dt.Columns.Add("product_name");
dt.Columns.Add("product_rate");
dt.Columns.Add("product_Quantity");
dt.Columns.Add("product_Amount");
}
protected void btnHome_Click(object sender, EventArgs e)
{
}
protected void gridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
SqlCommand cmd = new SqlCommand("select product_id,product_name,product_rate from product_detail", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
ddl.DataSource = ds;
ddl.DataTextField = "product_name";
ddl.DataValueField = "product_id";
ddl.DataBind();
}
}
protected void DropDownList1_SelectedindexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
SqlCommand cmd = new SqlCommand("select product_id,product_name,product_rate from product_detail", con);
SqlDataReader reader;
reader = cmd.ExecuteReader();
if (reader.Read())
{
}
}
}
}
i am unable to do how can i do that??
Thanks