Click here to Skip to main content
15,915,019 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using aspx Grid view bind it with data table ,i have /multiple lines of grid when it got bind my grid contains text boxes and i want to get value of that text box by using for each loop kindly guide to get this.. my button placed outside the grid
<html>
<dx:ASPxGridView ID="gvDunamicLedger" runat="server" AutoGenerateColumns="False" Width="100%" KeyFieldName="SellerID" Settings-HorizontalScrollBarMode="Auto" EnableTheming="True" Theme="Office2003Blue">
<columns> <dx:gridviewcommandcolumn showclearfilterbutton="True" visibleindex="0" visible="false" xmlns:dx="#unknown">







<dx:gridviewdatacolumn caption="Adjustment" unboundtype="Decimal" xmlns:dx="#unknown">
<dataitemtemplate>
<dx:ASPxTextBox ID="TAdjustment" runat="server" Width="130px"> <%--<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ValidationExpression="^(\d|,)*\.?\d*$" Font-Size="Small" ControlToValidate="TAdjustment" ForeColor="Red" ErrorMessage="Format: 1234,345,67890 OR 1234,345,67890.0"> <%-- <asp:TextBox ID="TextBox1" runat="server">--%>--%>



<dx:gridviewdatatextcolumn caption="Encash/Excess Amount" unboundtype="Decimal" xmlns:dx="#unknown">
<dataitemtemplate>
<dx:ASPxTextBox ID="TEncashAmount" runat="server" Width="130px">


<dx:gridviewdatatextcolumn caption="Disputed Amount" unboundtype="Decimal" xmlns:dx="#unknown">
<dataitemtemplate>
<dx:ASPxTextBox ID="TDisputedAmount" runat="server" Width="130px" >


<dx:gridviewdatatextcolumn caption="Remarks" unboundtype="Decimal" xmlns:dx="#unknown">
<dataitemtemplate>
<dx:ASPxMemo ID="TRemarks" runat="server" Width="130px">
<%--<dx:ASPxTextBox ID="TRemarks" runat="server" Width="170px">--%>




<settings showfilterrow="True">

<Styles AdaptiveDetailButtonWidth="22"></Styles>





my code is
C#
protected void Button1_Click(object sender, EventArgs e)
      {

          for (int i = 0; i < gvDunamicLedger.VisibleRowCount; i++)
          {



              ASPxTextBox tb = gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Adjustment"] as GridViewDataColumn, "TAdjustment") as ASPxTextBox;
              string payment = tb.Text;
              ObjInvoices.SellerID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "SellerID"));
              ObjInvoices.SellerTypeID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "SellerTypeID"));
              ObjInvoices.BuyerID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "BuyerID"));
              ObjInvoices.BuyerTypeID = Convert.ToInt32(gvDunamicLedger.GetRowValues(i, "BuyerTypeID"));
              ObjInvoices.BusinessAmount =Convert.ToDecimal(gvDunamicLedger.GetRowValues(i, "Payment"));
              ObjInvoices.SchemePaymentAmount = Convert.ToDecimal(gvDunamicLedger.GetRowValues(i, "SchemeAmount"));
              ASPxTextBox Adjustment = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Adjustment"] as GridViewDataColumn, "TAdjustment") as ASPxTextBox;
              ASPxTextBox EncashAmount = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Encash/Excess Amount"] as GridViewDataColumn, "TEncashAmount") as ASPxTextBox;
              ASPxTextBox DisputedAmount = (ASPxTextBox)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Disputed Amount"] as GridViewDataColumn, "TDisputedAmount") as ASPxTextBox;
              ASPxMemo Remarks = (ASPxMemo)gvDunamicLedger.FindRowCellTemplateControl(i, gvDunamicLedger.Columns["Remarks"] as GridViewDataColumn, "TRemarks") as ASPxMemo;





              String Adj = Adjustment.Text;
              String Encash = EncashAmount.Text;
              String Disputed =DisputedAmount.Text;
              String Remrk = (Remarks.Text).ToString();
              ObjInvoices.Adjustment =Convert.ToDecimal( Adj);
              ObjInvoices.EncashExcessAmount =Convert.ToDecimal( Encash);
              ObjInvoices.DisputedAmount = Convert.ToDecimal(Disputed);
              ObjInvoices.Remarks = Remrk;
              ObjInvoices.Insert();
              lblOutPut.Text = "insert";
          }
      }
Posted
Updated 4-Jan-16 19:14pm
v4

1 solution

Try:
C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TextBox myTextBox = (TextBox)(e.Row.Cells[1].FindControl("TextBoxName"));

            //Access yourTextbox here.
            string myString = TextBoxName.Text;
        }
    }
 
Share this answer
 
v3
Comments
Noman Suleman 5-Jan-16 1:09am    
i want to insert all grid record one time on click insert button which is placed out side grid
ridoy 5-Jan-16 1:34am    
OK, the try string myString = ((TextBox)GridViewName.Rows[i].FindControl("TextBoxName")).Text;

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