Click here to Skip to main content
15,867,453 members
Home / Discussions / C#
   

C#

 
GeneralRe: DateTime ISO 8601 Format Pin
OriginalGriff28-Sep-16 0:25
mveOriginalGriff28-Sep-16 0:25 
GeneralRe: DateTime ISO 8601 Format Pin
Ravi Bhavnani28-Sep-16 3:45
professionalRavi Bhavnani28-Sep-16 3:45 
GeneralRe: DateTime ISO 8601 Format Pin
tadhg8828-Sep-16 23:30
tadhg8828-Sep-16 23:30 
GeneralRe: DateTime ISO 8601 Format Pin
Daniel Pfeffer29-Sep-16 0:54
professionalDaniel Pfeffer29-Sep-16 0:54 
QuestionDatamodel for Survey Form Pin
Member 1204569227-Sep-16 22:57
Member 1204569227-Sep-16 22:57 
AnswerRe: Datamodel for Survey Form Pin
Gerry Schmitz28-Sep-16 8:09
mveGerry Schmitz28-Sep-16 8:09 
GeneralRe: Datamodel for Survey Form Pin
Member 1204569228-Sep-16 21:15
Member 1204569228-Sep-16 21:15 
QuestionColumn sum of multiple columns of dynamic gridview using Javascript Pin
SREENATH GANGA27-Sep-16 21:57
SREENATH GANGA27-Sep-16 21:57 
I have a Dynamic asp Gridview with all columns as template feild TextBox. The columns of the Gridview are also dynamic and column count may vary everytime.

Please find code below
C#
public void FillPoDetails()
       {

           DataTable dt = new DataTable();

           dt = pmdata.createdatatable(int.Parse(Session["OurStyleid"].ToString()), int.Parse(Session["PoPackid"].ToString()));



        GenerateTable(dt.Columns.Count, dt.Rows.Count,dt);

           foreach (DataColumn col in dt.Columns)
           {
               //Declare the bound field and allocate memory for the bound field.
               TemplateField bfield = new TemplateField();

               //Initalize the DataField value.
               bfield.HeaderTemplate = new ArtWebApp.Controls.GridViewTemplate(ListItemType.Header, col.ColumnName);

               //Initialize the HeaderText field value.
               bfield.ItemTemplate = new ArtWebApp.Controls.GridViewTemplate(ListItemType.Item, col.ColumnName);

               //Add the newly created bound field to the GridView.
               GrdDynamic.Columns.Add(bfield);
           }



           GrdDynamic.DataSource = dt;
           GrdDynamic.DataBind();

       }
      public GridViewTemplate(ListItemType type, string colname)
           {
               //Stores the template type.
               _templateType = type;

               //Stores the column name.
               _columnName = colname;
           }

       void ITemplate.InstantiateIn(System.Web.UI.Control container)
           {
               switch (_templateType)
               {
                   case ListItemType.Header:
                       //Creates a new label control and add it to the container.
                       Label lbl = new Label();            //Allocates the new label object.
                       lbl.Text = _columnName;
                       lbl.CssClass = "Headerclass";
                           //Assigns the name of the column in the lable.
                       container.Controls.Add(lbl);        //Adds the newly created label control to the container.
                       break;

                   case ListItemType.Item:
                       //Creates a new text box control and add it to the container.
                       TextBox tb1 = new TextBox();                            //Allocates the new text box object.
                       tb1.DataBinding += new EventHandler(tb1_DataBinding);   //Attaches the data binding event.
                       tb1.Columns =6;                                        //Creates a column with size 4.
                                                                              // tb1.Width = System.Web.UI.WebControls.Unit.Percentage(100);
                       tb1.Width = 100;
                       tb1.Wrap = true;
                       tb1.ID = "txt_" + _columnName;
                       if(_columnName== "ColorTotal")
                       {
                           tb1.CssClass = "ColorTotal";
                       }
                       else if (_columnName == "Color")
                       {
                           tb1.CssClass = "Color";
                       }
                       else
                       {
                           tb1.CssClass = "txtCalQty";
                           tb1.Attributes.Add("onkeypress", "return isNumberKey(event,this)");
                           tb1.Attributes.Add("onkeyup", "sumofQty(this)");
                       }

                       container.Controls.Add(tb1);                            //Adds the newly created textbox to the container.

                       break;


               }
           }


And inorder to get the row total I had added a Javascript function on keydown event and its working clearly

JavaScript
//calculate the sum of qty on keypress
       function sumofQty(objText) {
       
        
           var cell = objText.parentNode;
           
           var row = cell.parentNode;

           var sum = 0;
           var textboxs = row.getElementsByClassName("txtCalQty");

           for (var i = 0; i < textboxs.length; i++)
           {
               sum += parseFloat(textboxs[i].value);
           }
           var textboxtotalqtys = row.getElementsByClassName("ColorTotal");
           textboxtotalqtys[0].value = sum.toString();         

       }



can anyone please help me in finding out the sum of each columns(all same cssclass).and display it in the Sizetotal row because I am not able to loop through columns
AnswerRe: Column sum of multiple columns of dynamic gridview using Javascript Pin
Pete O'Hanlon27-Sep-16 23:20
subeditorPete O'Hanlon27-Sep-16 23:20 
QuestionDelegates with Events Pin
Member 1116162526-Sep-16 18:01
Member 1116162526-Sep-16 18:01 
AnswerRe: Delegates with Events Pin
Pete O'Hanlon26-Sep-16 19:36
subeditorPete O'Hanlon26-Sep-16 19:36 
GeneralRe: Delegates with Events Pin
Rahul VB27-Sep-16 23:04
professionalRahul VB27-Sep-16 23:04 
QuestionError Making Method Async Pin
Kevin Marois24-Sep-16 12:13
professionalKevin Marois24-Sep-16 12:13 
AnswerRe: Error Making Method Async Pin
George Swan24-Sep-16 12:43
mveGeorge Swan24-Sep-16 12:43 
AnswerRe: Error Making Method Async Pin
Pete O'Hanlon24-Sep-16 21:31
subeditorPete O'Hanlon24-Sep-16 21:31 
SuggestionRe: Error Making Method Async Pin
Richard Deeming26-Sep-16 1:52
mveRichard Deeming26-Sep-16 1:52 
QuestionCancelRequest not work! Pin
Programmer 124-Sep-16 7:13
Programmer 124-Sep-16 7:13 
AnswerRe: CancelRequest not work! Pin
Eddy Vluggen24-Sep-16 11:48
professionalEddy Vluggen24-Sep-16 11:48 
GeneralRe: CancelRequest not work! Pin
Programmer 124-Sep-16 19:31
Programmer 124-Sep-16 19:31 
GeneralRe: CancelRequest not work! Pin
Eddy Vluggen26-Sep-16 4:53
professionalEddy Vluggen26-Sep-16 4:53 
QuestionStrange problem in Exception handling Pin
Programmer 123-Sep-16 21:44
Programmer 123-Sep-16 21:44 
AnswerRe: Strange problem in Exception handling Pin
OriginalGriff23-Sep-16 22:36
mveOriginalGriff23-Sep-16 22:36 
GeneralRe: Strange problem in Exception handling Pin
Programmer 124-Sep-16 0:28
Programmer 124-Sep-16 0:28 
Questionhow to display alert in system tray using c# Pin
Member 308047023-Sep-16 2:18
Member 308047023-Sep-16 2:18 
AnswerRe: how to display alert in system tray using c# Pin
Pete O'Hanlon23-Sep-16 2:23
subeditorPete O'Hanlon23-Sep-16 2:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.