Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys, I have a Gridview which binds some data from database except Quantity Textbox. There is also a button on Grid on each click of this button one number is added to the quantity box (This I want to show on grid). Please see my code below & suggest me.

XHTML :

ASP.NET
<asp:TextBox Style="width:32px; height:10px; position:absolute;" ID="txtDisplay" runat="server" AutoPostBack="True" OnTextChanged="txtDisplay_TextChanged"></asp:TextBox>
                                                                      <asp:Button ID="btn_Next" runat="server" CommandName="Next" CommandArgument='<%#((GridViewRow)Container).RowIndex %>' Text=">" />

Code:
C#
protected void grdSale_RowCommand(object sender, GridViewCommandEventArgs e)
    {

C#
if (e.CommandName == "Next")
       {
           int Index_Next = Convert.ToInt32(e.CommandArgument);
           TextBox Quantity = (TextBox)grdSale.Rows[Index_Next].FindControl("txtDisplay");
           int Val_Next = Convert.ToInt32(Quantity.Text);
           if (Val_Next != 0 && Val_Next > 1)
           {
               Val_Next = Val_Next + 1;
           }
           (TextBox)grdSale.Rows[Index_Next].FindControl("txtDisplay") = Val_Next.ToString();    // Here I'm getting error. I also convert this string to TextBox but still show error.
       }


Kindly suggest your experience.
Posted

1 solution

Hi Guys I done like this :

C#
((TextBox)grdSale.Rows[Index_Next]
                 .FindControl("txtDisplay")).Text = Val_Next.ToString();
 
Share this answer
 

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