TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
selvi subramanian
NA
799
571.8k
i have to retrieve the value from sqlserver
Sep 12 2013 5:02 AM
i have to retrieve the value from sqlserver 2008.
my design is
<table align="center" style="border-color: #1d599e; border-style: outset;border-width: thin; background-color: #D7D7D7; width:50%">
<tr style="margin-left: 80px; background:#1d599e;" align="center" colspan="2">
<td class="style2" style="margin-left: 80px; background:#1d599e;" align="center">
Billing Details
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="Product"></asp:Label>
</td>
<td>
<asp:DropDownList ID="DropDownList3" runat="server" Height="16px" Width="132px"
AppendDataBoundItems="True" AutoPostBack="True"
onselectedindexchanged="DropDownList3_SelectedIndexChanged">
<asp:ListItem>--Select Product--</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="BillNo"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtbillno" runat="server"></asp:TextBox>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
onrowdatabound="GridView1_RowDataBound" Width="100px">
<Columns>
<asp:TemplateField HeaderText="Choose">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="ItemName" DataField="brandname" Visible="false"/>
<asp:TemplateField HeaderText="ItemName">
<ItemTemplate>
<asp:TextBox ID="itname" runat="server" Text='<%#Bind("brandname")%>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:DropDownList ID="ddlw" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlw_SelectedIndexChanged">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="RequiredNo">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Value="0">Choose</asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6</asp:ListItem>
<asp:ListItem>7</asp:ListItem>
<asp:ListItem>8</asp:ListItem>
<asp:ListItem>9</asp:ListItem>
<asp:ListItem>10</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cost">
<ItemTemplate>
<asp:TextBox ID="pprc" runat="server" ></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="beforevat">
<ItemTemplate>
<asp:TextBox ID="bfvata" runat="server" ontextchanged="bfvata_TextChanged"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Extra">
<ItemTemplate>
<asp:TextBox ID="txextra" runat="server" ontextchanged="txextra_TextChanged" AutoPostBack="true"
></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CorrectPrice">
<ItemTemplate>
<asp:TextBox ID="txtcc" runat="server" ontextchanged="txtcc_TextChanged" AutoPostBack="true"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ActualPrice">
<ItemTemplate>
<asp:TextBox ID="txtactl" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="VAT">
<ItemTemplate>
<asp:TextBox ID="txvat" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="TotalAmount">
<ItemTemplate>
<asp:TextBox ID="txtamt" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td colspan="2">
</td>
<td>
</td>
</tr>
</table>
mycode 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");
DataSet ds = new DataSet();
REMO sel = new REMO();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
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 distinct brandname from demo1 where productname='"+DropDownList3.SelectedItem.Text+"'", 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");
var name=Convert.ToString(((TextBox)e.Row.FindControl("itname")).Text);
//int CountryId = Convert.ToInt32(e.Row.Cells[0].Text);
SqlCommand cmd = new SqlCommand("select distinct weight from demo1 where brandname='"+name+"'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
ddl.DataSource = ds;
ddl.DataTextField = "weight";
ddl.DataValueField = "weight";
//ddl.DataValueField = "StateID";
ddl.DataBind();
ddl.Items.Insert(0, new ListItem("--Select--", "0"));
// float sllv = Convert.ToSingle((TextBox)GridView1.FindControl("pprice"));
//float scv = Convert.ToSingle((DropDownList)GridView1.FindControl("DropDownList1"));
// TextBox sllv = e.Row.FindControl("pprce") as TextBox;
// DropDownList scv = e.Row.FindControl("DropDownList1") as DropDownList;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in GridView1.Rows)
{
float sllv = Convert.ToInt32(((TextBox)gvrow.FindControl("pprce")).Text);
float scv = Convert.ToInt32(((DropDownList)gvrow.FindControl("DropDownList1")).SelectedValue);
((TextBox)gvrow.FindControl("bfvata")).Text = Convert.ToString(sllv * scv);
string kishh=((TextBox)gvrow.FindControl("bfvata")).Text;
((TextBox)gvrow.FindControl("txtcc")).Text = Convert.ToString(int.Parse(kishh) * (14.5 / 100));
string kishore = ((TextBox)gvrow.FindControl("txtcc")).Text;
// ((TextBox)e.Row.FindControl("bfvata")).Text = Convert.ToString(sllv * scv);
}
}
protected void txextra_TextChanged(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in GridView1.Rows)
{
float ses, sddd, pry;
string cs = ((TextBox)gvrow.FindControl("txtcc")).Text;
string hds = ((TextBox)gvrow.FindControl("bfvata")).Text;
string kish = ((TextBox)gvrow.FindControl("txtactl")).Text;
ses = float.Parse(cs);
sddd = float.Parse(hds);
//pry = float.Parse(kish);
//pry = float.Parse(kish);
pry = (ses + sddd);
((TextBox)gvrow.FindControl("txtactl")).Text = pry.ToString();
// string amam = ((TextBox)gvrow.FindControl("txtactl")).Text;
}
//foreach (GridViewRow gvrow in GridView1.Rows)
//{
// float gun = Convert.ToInt32(((TextBox)gvrow.FindControl("bfvata")).Text);
// float gs = Convert.ToInt32(((TextBox)gvrow.FindControl("txextra")).Text);
// ((TextBox)gvrow.FindControl("txtcc")).Text = Convert.ToString(gun + gs);
//}
//txtcc
}
protected void bfvata_TextChanged(object sender, EventArgs e)
{
}
protected void txtcc_TextChanged(object sender, EventArgs e)
{
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
LoadData();
}
protected void ddlw_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow gvrow in GridView1.Rows)
{
var wegt = ((DropDownList)gvrow.FindControl("ddlw")).Text;
SqlCommand cmd = new SqlCommand("select price from demo1 where weight='" + wegt + "'",con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables["price"];
GridView1.DataBind();
}
i need if i choose the quantity as 25 i need the price for that particular quantity. but the data set is empty
Reply
Answers (
10
)
How to Convert Decimal To Dollar
How to read xml files from App.config file path?