Search code examples
c#asp.netdevexpressaspxgridview

How can I access the aspx grid from code behind?


I would like to do something like this with an aspx grid as well. Create an object of the Grid and set its properties form code behind This is for an asp grid

GridView obj1=(GridView)sender;
BoundField col = (BoundField)grid.Columns[1];
col1.DataFormatString="{0:N2}";

Your thoughts please?

And if you are willing to help further , I would appreciate your thoughts on this question that I posted. I have been waiting for ages to get some suggestions for this question.

How to Set the column properties of DevEx Grid form code behind


Solution

  • foreach (GridDataItem item in grdInvoiceItems.Items)
    {
              //object id = (object)item.OwnerTableView.DataKeyValues[item.ItemIndex]["Id"];
              object value = item["Id"].Text;
              id = (item["Id"].FindControl("lblId") as RadTextBox).Text;
              string lineItem = (item["Item"].FindControl("ddlItems") as RadComboBox).Text;
              string description = (item["Description"].FindControl("txtDescription") as RadTextBox).Text;
              double? price = (item["Price"].FindControl("txtPrice") as RadNumericTextBox).Value;
              double? qty = (item["Qty"].FindControl("txtQty") as RadNumericTextBox).Value;
              double? discount = (item["Discount"].FindControl("txtDiscount") as RadNumericTextBox).Value;
              //double tax = double.Parse(lblTaxes.Text);
              //Label amount1 = (item["Amount"].FindControl("lblAmount") as Label);
              //string amount = item["Amount"].Text;
              //Label amount1 = (item.FindControl("lblAmount") as Label);
              double? amounnt = (item["Amount"].FindControl("lblAmount") as RadNumericTextBox).Value;
    
              if (!string.IsNullOrEmpty(lineItem))
              {
                  Invoice.UpdateInvoiceItems(Convert.ToInt32(id), lineItem, description, Convert.ToDouble(price),
                      Convert.ToInt32(qty), Convert.ToDouble(discount), 0, Convert.ToDouble(amounnt));
              }
          }