Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 columns in gridview having textboxes length, width and area. When i enter length then i have to click twice in textbox to enter width because autopotback property is true and calculating area on textchange event. i have tried with update panel but not working..is there any solution for this.
Posted
Comments
King Fisher 24-Dec-14 1:45am    
Show your Gridview Design with Update Panel

1 solution

Try like this.!



ASP.NET
Aspx Page looks like below


 <form id="form1" runat="server">
    <asp:scriptmanager runat="server" xmlns:asp="#unknown">
    </asp:scriptmanager>
    <asp:updatepanel runat="server" xmlns:asp="#unknown">
        <contenttemplate>
            <asp:gridview id="grdResult" runat="server" autogeneratecolumns="false">
                <columns>
                    <asp:templatefield headertext="Length">
                        <itemtemplate>
                            <asp:textbox id="TxtLength" runat="server" text="<%#Bind("Length") %>" ontextchanged="TxtLength_TextChanged">
                                        AutoPostBack="true"></asp:textbox>
                        </itemtemplate>
                    </asp:templatefield>
                    <asp:templatefield headertext="Width">
                        <itemtemplate>
                                    <asp:textbox id="TxtWidth" runat="server" text="<%#Bind("Width") %>" ontextchanged="TxtWidth_TextChanged">
                                        AutoPostBack="true"></asp:textbox>
                        </itemtemplate>
                    </asp:templatefield>
                    <asp:templatefield headertext="Area">
                        <itemtemplate>
                            <asp:textbox id="TxtArea" runat="server" text="<%#Bind("Area") %>" ontextchanged="TxtArea_TextChanged">
                                        AutoPostBack="true"></asp:textbox>
                        </itemtemplate>
                    </asp:templatefield>
                </columns>
            </asp:gridview>
        </contenttemplate>
    </asp:updatepanel>
    </form>


code behind page looks like below

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Length", typeof(Double));
                dt.Columns.Add("Width", typeof(Double));
                dt.Columns.Add("Area", typeof(Double));


                for (int i = 0; i < 10; i++)
                {
                    DataRow dr = dt.NewRow();

                    dr["Length"] = 1;
                    dr["Width"] = 1;
                    dr["Area"] = 1;
                    dt.Rows.Add(dr);
                }


                grdResult.DataSource = dt;
                grdResult.DataBind();
            }
        }

        protected void TxtLength_TextChanged(object sender, EventArgs e)
        {

        }
        protected void TxtWidth_TextChanged(object sender, EventArgs e)
        {

        }
        protected void TxtArea_TextChanged(object sender, EventArgs e)
        {

        }
 
Share this answer
 
v3
Comments
King Fisher 24-Dec-14 1:44am    
Update Solution 1 Instead of Creating another solution
Praveen Kumar Upadhyay 24-Dec-14 2:56am    
Vinay, Try to put proper code instead of putting multiple solution. Also make sure that your solution should solve the problem.
vinay.tatipamula 24-Dec-14 4:36am    
Thanks praveen kumar upadhyay, the solution what i shared should work and it is working..!
Member 9579525 25-Dec-14 3:08am    
code..same as above but not working..have u tried in VS 8/10/12 or 13?

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>
<asp:GridView ID="GrdViewCS" runat="server" AutoGenerateColumns="false">
<columns>
<asp:TemplateField HeaderText="Length">
<itemtemplate>
<asp:TextBox ID="TxtLength" runat="server" Text='<%#Bind("Length")%>' AutoPostBack="true"
BackColor="Transparent" OnTextChanged="TxtLength_TextChanged">


<asp:TemplateField HeaderText="Width">
<itemtemplate>
<asp:TextBox ID="TxtWidth" runat="server" Text='<%#Bind("Width")%>' AutoPostBack="true"
BackColor="Transparent" OnTextChanged="TxtWidth_TextChanged">


<asp:TemplateField HeaderText="Area">
<itemtemplate>
<asp:TextBox ID="TxtArea" runat="server" Text='<%#Bind("Area")%>' BackColor="Transparent"
ReadOnly="true">






<div>
</div>
</form>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900