selvi subramanian

selvi subramanian

  • NA
  • 799
  • 571.7k

Need to affect Last Enter Value in viewstate in asp.net RSS

Jul 20 2015 5:11 AM
my design
 
<table align="center" cellpadding="2" cellspacing="0" border="1" style="width: 900px; height: 100px;border: #04AFEF; background-color: White" id="Tabl">
<tr><td class="style1"><asp:Label ID="SalesNo" runat="server" Text="Sales No"></asp:Label></td>
<td><asp:Label ID="Terms" runat="server" Text="Terms"></asp:Label></td>
<td><asp:Label ID="SalesDate" runat="server" Text="Sales Date"></asp:Label></td>
<td><asp:Label ID="CustomerName" runat="server" Text="Customer Name"></asp:Label></td>
<td class="style3"><asp:Label ID="CounterName" runat="server" Text="CounterName"></asp:Label></td>
<td class="style3"><asp:Label ID="PreviosBillamount" runat="server" Text="Previous Bill Amount"></asp:Label></td></tr>
<tr><td><asp:TextBox ID="txtsalesno" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtTerms" runat="server">Cash</asp:TextBox></td>
<td><asp:TextBox ID="txtSalesDate" runat="server"></asp:TextBox></td>
<td><asp:DropDownList ID="ddCustomerName" runat="server" Height="18px" Width="126px"></asp:DropDownList></td>
<td><asp:DropDownList ID="ddCounterName" runat="server" Height="16px" Width="153px"></asp:DropDownList></td>
<td><asp:TextBox ID="txtPreviosBillamount" runat="server"></asp:TextBox></td></tr>
<tr><td><asp:Label ID="SalesPerson" runat="server" Text="Sales Person"></asp:Label></td>
<td><asp:Label ID="Barcode" runat="server" Text="Barcode"></asp:Label></td>
<td><asp:Label ID="Qty" runat="server" Text="Qty"></asp:Label></td>
<td><asp:Label ID="Rate" runat="server" Text="Rate"></asp:Label></td>
<td><asp:Label ID="Discount" runat="server" Text="Discount %"></asp:Label></td>
<td><asp:Label ID="Discountrs" runat="server" Text="Discount rs"></asp:Label></td></tr>
<tr><td><asp:DropDownList ID="ddSalesPerson" runat="server" Height="17px"
Width="111px"></asp:DropDownList></td>
<td><asp:TextBox ID="txtBarcode" runat="server" AutoPostBack="True" ontextchanged="txtBarcode_TextChanged" onkeypress = "return KeyCode()"></asp:TextBox></td>
<td><asp:TextBox ID="txtqty" runat="server" ontextchanged="txtqty_TextChanged" AutoPostBack="True" onkeypress = "return KeyCode()"></asp:TextBox></td>
<td><asp:TextBox ID="txtrate" runat="server"></asp:TextBox></td>
<td><asp:TextBox ID="txtdispr" runat="server" AutoPostBack="True"
ontextchanged="txtdispr_TextChanged"></asp:TextBox></td>
<td><asp:TextBox ID="txtdisrs" runat="server"></asp:TextBox></td></tr>
<tr><td colspan="6">
<asp:GridView ID="ddsales" runat="server" Width="807px"
AutoGenerateColumns="false" onrowdatabound="ddsales_RowDataBound"
onselectedindexchanged="ddsales_SelectedIndexChanged"
onrowcommand="ddsales_RowCommand" ShowFooter="True"
onrowdeleting="ddsales_RowDeleting"
onselectedindexchanging="ddsales_SelectedIndexChanging"
onprerender="ddsales_PreRender" onrowcreated="ddsales_RowCreated">
<Columns>
<asp:TemplateField ControlStyle-Width="20px">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" AutoPostBack="True" oncheckedchanged="chkSelect_CheckedChanged">
</asp:CheckBox>
</ItemTemplate> <ItemStyle Width="20px" />
<ControlStyle Width="20px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Sectionname" ControlStyle-Width="120px"><ItemTemplate><asp:Label ID="lblsectn" runat="server" Text="<%#bind('sectionname') %>"></asp:Label> </ItemTemplate><ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /> </asp:TemplateField>
<asp:TemplateField HeaderText="Product Name" ControlStyle-Width="120px"><ItemTemplate><asp:Label ID="lblproductname" runat="server" Text="<%#bind('productname') %>"></asp:Label></ItemTemplate><ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /></asp:TemplateField>
<asp:TemplateField HeaderText="Lotno" ControlStyle-Width="120px"><ItemTemplate><asp:Label ID="lbllotno" runat="server" Text="<%#bind('lotno') %>"></asp:Label></ItemTemplate><ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /></asp:TemplateField>
<asp:TemplateField HeaderText="MRP" ControlStyle-Width="120px"><ItemTemplate><asp:Label ID="lblmrp" runat="server" Text="<%#bind('mrp') %>"></asp:Label></ItemTemplate>
<FooterTemplate><asp:Label ID="Salary" runat="server" /></FooterTemplate>
<ItemStyle Width="120px" VerticalAlign="Bottom" /><ControlStyle Width="120px" /></asp:TemplateField>
</Columns>
</asp:GridView>
</td></tr>
<tr><td colspan="4">
<asp:Button ID="btRemove" runat="server" Text="Remove" onclick="btRemove_Click"
Width="170px" />
<asp:Button ID="Button1" runat="server" Text="Clear All" Width="170px"
onclick="Button1_Click" />
</td></tr>
</table>
 
 
 
 
 
my code
 
 
private void BindListView()
{
string constr = ConfigurationManager.AppSettings["s"].ToString();
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
cmd.CommandText = "SELECT distinct sectionname,lotno,Productname,mrp from purchasedummy where lotno='" + txtBarcode.Text + "'";
cmd.Connection = con;
//cmd.Parameters.AddWithValue("@PurchaseNo", Convert.ToInt32(this.barcodetx.Text.Trim()));
//cmd.Parameters.AddWithValue("@Qty", Convert.ToInt32(this.qty.Text.Trim()));
DataTable dt = new DataTable();
sda.Fill(dt);
DataTable products = new DataTable();
if (ViewState["Products"] == null)
{
products.Merge(dt, true);
}
else
{
products = (DataTable)ViewState["Products"];
products.Merge(dt, true);
}
ViewState["Products"] = products;
ddsales.DataSource = products;
ddsales.DataBind();
}
}
}
}
 
 
 
protected void txtqty_TextChanged(object sender, EventArgs e)
{
foreach (GridViewRow rowz in ddsales.Rows)
{
double mr, wt, totlrp;
mr =Convert.ToDouble((rowz.FindControl("lblmrp") as Label).Text);
wt = double.Parse(txtqty.Text);
totlrp = mr * wt;
(rowz.FindControl("lblmrp") as Label).Text = Convert.ToString(totlrp);
}
txtqty.Text = "1";
}