Ticket T114245
Visible to All Users

How to fetch textbox values from the aspxgridview

created 11 years ago

I have inserted textbox inside GridViewBandColumn using InstantiateIn method.Now on click of save button, I have to fetch the value from the textbox.
How do I fetch the value from gridbandcolumn on click of save button
GridViewBandColumn Total = new GridViewBandColumn();
Total.Caption =
Convert.ToString(z.Item3);
Total.HeaderTemplate =
new TotalQuantity(Total.Caption);
Total.Name =
"TotalQuantity";

public
class TotalQuantity : ITemplate
{private string qty;
  private static int count = 0;
 private int id;
    public TotalQuantity(string y)
{
        this.qty = y;
       this.id= ++count;
}

public void InstantiateIn(Control container)
{
 ASPxTextBox txtTotal = new ASPxTextBox();

txtTotal.ID =

"txtTotal"+id;

GridViewHeaderTemplateContainer gridContainer = (GridViewHeaderTemplateContainer)container;

txtTotal.Text = qty
txtTotal.BackColor =

Color.Transparent;
container.Controls.Add(txtTotal);

}
}

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,

I think that you can use the ASPxGridView.FindHeaderTemplateControl method to get a reference to the ASPxTextBox placed in a column header.

Let us know if you face difficulties with this approach. In this case it would be helpful if you provide us with additional information about your scenario and with a sample runnable project.

    Other Answers

    created 11 years ago

    ASPxTextBox text2 = gvConsumption.FindHeaderTemplateControl(gvConsumption.AllColumns[1], "txtTotal2") as ASPxTextBox;

    ASPxTextBox text3 = gvConsumption.FindHeaderTemplateControl(gvConsumption.AllColumns[2], "txtTotal3") as ASPxTextBox;

    ASPxTextBox text4 = gvConsumption.FindHeaderTemplateControl(gvConsumption.AllColumns[3], "txtTotal4") as ASPxTextBox;

    ASPxTextBox text5 = gvConsumption.FindHeaderTemplateControl(gvConsumption.AllColumns[4], "txtTotal5") as ASPxTextBox;

    string totalQuantity2 = text2.Text;

    string totalQuantity3 = text3.Text;

    string totalQuantity4 = text4.Text;

    I tried this method.But how do i know in which column the textbox exist.
    I tried getting the column number…but it is showing null values in TEXT2,TEXT3…
    I have attached the images

      Show previous comments (8)

        its working but in my case i wil be binding the gridatacolumn and data during run time.I cannot just call only one gridbandcolumn during pageinit.In my case in ADDCOLUMN method,i wil be binding the gridview,so each time pageinit method is called ,my gridview is binding many times and i wil lose all data in batch edit and i am not getting textbox values.
        so i want to know how to fetch textbox values without affecting batch edit and my whole gridview is generated dynamically.
        I have attached the file

        Alessandro (DevExpress Support) 11 years ago

          Hi,

          We are working on your problem and need some additional time to research it in greater detail. We will let you know of our progress once we have any results. I hope you will excuse any delay that may arise.

          Alessandro (DevExpress Support) 11 years ago

            Thank you for your patience. I have examined this issue with our developers. We concluded that it occurs because when such complex hierarchy of controls is created dynamically, there is no guarantee that post data will be applied at the moment you expect it to be. Our developers recommend that you apply the post data forcibly as follows:

            C#
            protected void gvasp_BatchUpdate(object sender, DevExpress.Web.Data.ASPxDataBatchUpdateEventArgs e) { ASPxTextBox txtTotal1 = gvasp.FindHeaderTemplateControl(gvasp.Columns["TotalQuantity1"], "txtTotal1") as ASPxTextBox; ASPxTextBox txtTotal2 = gvasp.FindHeaderTemplateControl(gvasp.Columns["TotalQuantity2"], "txtTotal2") as ASPxTextBox; ASPxTextBox txtTotal3 = gvasp.FindHeaderTemplateControl(gvasp.Columns["TotalQuantity3"], "txtTotal3") as ASPxTextBox; IPostBackDataHandler control1 = txtTotal1 as IPostBackDataHandler; control1.LoadPostData(txtTotal1.UniqueID, Page.Request.Params); control1 = txtTotal2 as IPostBackDataHandler; control1.LoadPostData(txtTotal2.UniqueID, Page.Request.Params); control1 = txtTotal3 as IPostBackDataHandler; control1.LoadPostData(txtTotal3.UniqueID, Page.Request.Params); ...

            I have corrected your sample accordingly. Thank you for your time and cooperation in advance.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.