What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 4706 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > ASP.NET > TextBox Change Event Inside GridView ...
Ranjeet_8

TextBox Change Event Inside GridView

 Code Snippet posted by: Ranjeet_8 | Posted on: 8/16/2012 | Category: ASP.NET Codes | Views: 2265 | Status: [Member] | Points: 40 | Alert Moderator   


Aspx Design Page :

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Testing Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="S No.">
<ItemTemplate>
<asp:Label ID="lblSn" runat="server" Text='<%#Eval("Sno") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Price">
<ItemTemplate>
<asp:Label ID="lblRs" runat="server" Text='<%#Eval("Price") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:TextBox ID="txtQty" runat="server" Text="0" OnTextChanged="txtQty_TextChanged"
AutoPostBack="True"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Amt.">
<ItemTemplate>
<asp:Label ID="lblTotalRs" runat="server" Text="0"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
</html>

C# Code :
 

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Create DataTable
DataTable dt = new DataTable();
dt.Columns.Add("Sno");
dt.Columns.Add("Price");
DataRow dr;
dr = dt.NewRow(); // Add New Row In DataTable
dr["Sno"] = "1";
dr["Price"] = "104";
dt.Rows.Add(dr);
dr = dt.NewRow(); // Add New Row In DataTable
dr["Sno"] = "2";
dr["Price"] = "600";
dt.Rows.Add(dr);
// Bind Your GridView
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
// TextBox Change Event.
protected void txtQty_TextChanged(object sender, EventArgs e)
{
TextBox txt = (TextBox)sender;
GridViewRow gvRow = (GridViewRow)txt.Parent.Parent;
Label lblRs = (Label)gvRow.FindControl("lblRs");
Label lblTotalRs = (Label)gvRow.FindControl("lblTotalRs");
try
{
lblTotalRs.Text = ((Convert.ToInt32(txt.Text)) * (Convert.ToInt32(lblRs.Text))).ToString();
}
catch { lblTotalRs.Text = "0"; txt.Text = "0"; }
}

Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 12:46:05 AM