Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi
 
I have a grid view, and I'm adding rows to that gridview in javascript.
Now the problem is when I click on submit button,
I need to loop through the gridview in code behind.
But while page load, the grid is getting rendered and getting empty, hence no rows in the loop.
 
the code bits are like below..
 
<asp:GridView ID="grdCase" runat="server" AutoGenerateColumns="False">
                                            <Columns>
                                                <asp:BoundField DataField="Providername" HeaderText="Providername" HeaderStyle-Width="200px" />
                                                <asp:BoundField DataField="DOA" HeaderText="DOA" HeaderStyle-Width="50px" />
                                                <asp:BoundField DataField="DOD" HeaderText="DOD" HeaderStyle-Width="50px" />
                                                <asp:BoundField DataField="ReceiptNo" HeaderText="ReceiptNo" HeaderStyle-Width="50px"
                                                    DataFormatString="{0:c}" />
                                                <asp:BoundField DataField="ReceiptDate" HeaderText="ReceiptDate" HeaderStyle-Width="50px" />
                                                <asp:BoundField DataField="ReceiptAmount" HeaderText="ReceiptAmount" HeaderStyle-Width="50px" />
                                                <asp:BoundField DataField="ApprovedAmount" HeaderText="ApprovedAmount" HeaderStyle-Width="50px"
                                                    DataFormatString="{0:c}" />
                                                <asp:BoundField DataField="WageType" HeaderText="WageType" HeaderStyle-Width="50px" />
                                                <asp:BoundField DataField="VisitType" HeaderText="VisitType" HeaderStyle-Width="50px" />
                                                <asp:BoundField DataField="ClaimType" HeaderText="Claim Type" HeaderStyle-Width="50px" />
                                            </Columns>
                                        </asp:GridView>
 

 
JAVASCRIPT :
 
 function AddNewRecord() {
            var grd = document.getElementById("<%= grdCase.ClientID %>");
 
            var tr = document.createElement("tr");
 
            var cell1 = document.createElement("td");
            var cell2 = document.createElement("td");
            var cell3 = document.createElement("td");
            var cell4 = document.createElement("td");
            var cell5 = document.createElement("td");
            var cell6 = document.createElement("td");
            var cell7 = document.createElement("td");
            var cell8 = document.createElement("td");
            var cell9 = document.createElement("td");
            var cell10 = document.createElement("td");
            var cell11 = document.createElement("td");
 

 

            if (document.getElementById("<%= divProviderTextbox.ClientID %>").style.display == 'block') {
                var txtProviderName = document.getElementById("<%= txtProviderName.ClientID %>").value;
            }
            else if (document.getElementById("<%= divProviderDropDown.ClientID %>").style.display == 'block') {
                var txtProviderName = document.getElementById("<%= ddlProvider.ClientID %>").value;
            }
            var txtTreatmentDate = document.getElementById("<%= txtTeatmentDt.ClientID %>").value;
            var txtDOA = document.getElementById("<%= txtDOA.ClientID %>").value;
            var txtDOD = document.getElementById("<%= txtDOD.ClientID %>").value;
            var txtReceiptNo = document.getElementById("<%= txtReceiptNo.ClientID %>").value;
            var txtReceiptDt = document.getElementById("<%= txtReceiptDt.ClientID %>").value;
            var txtReceiptAmt = document.getElementById("<%= txtReceiptAmt.ClientID %>").value;
            var txtApprovedAmt = document.getElementById("<%= txtApprovedAmt.ClientID %>").value;
            var SelectedWage = document.getElementById("<%= ddlWageType.ClientID %>").value;
            var VisitType = document.getElementById("<%= lblVisitType.ClientID %>").innerHTML;
            var ClaimType = document.getElementById("<%= lblClaimType.ClientID %>").innerHTML;
            var bt = document.createElement('button');
 
            cell1.innerHTML = txtProviderName;
            if (VisitType == 'InPatient') {
                cell2.innerHTML = txtDOA;
                cell3.innerHTML = txtDOD;
            }
            else {
                cell3.innerHTML = txtTreatmentDate;
            }
            cell4.innerHTML = txtReceiptNo;
            cell5.innerHTML = txtReceiptDt;
            cell6.innerHTML = txtReceiptAmt;
            cell7.innerHTML = txtApprovedAmt;
            cell8.innerHTML = SelectedWage;
            if (VisitType == 'InPatient') {
                cell9.innerHTML = 'I';
            }
            else {
                cell9.innerHTML = 'O';
            }
            cell10.innerHTML = ClaimType;
            cell11.innerHTML = "<input id='delete' type='Submit' name='Remove' value='Remove' onclick ='javascript:return remove(this);' />";
 
            tr.appendChild(cell1);
            tr.appendChild(cell2);
            tr.appendChild(cell3);
            tr.appendChild(cell4);
            tr.appendChild(cell5);
            tr.appendChild(cell6);
            tr.appendChild(cell7);
            tr.appendChild(cell8);
            tr.appendChild(cell9);
            tr.appendChild(cell10);
            tr.appendChild(cell11);
 

            var tbod = grd.rows[0].parentNode;
            //var newRow = grd.rows[grd.rows.length - 1].cloneNode(true);
            tbod.appendChild(tr);
            return false;
 
        }
 
Can anybody help me in this aspect..
 
Thanks in anticipation.
 
Sri
Posted 28-Apr-13 19:42pm
Comments
Rohan Leuva at 29-Apr-13 0:55am
   
You have not showed page_load code.Well,i suspect that you are filling gridview on pageload from database,then if you added data from above code then where have you stored it?so on every page load,regardless of data inserted,it is getting old values only.
cyanceenu at 29-Apr-13 1:01am
   
Yes Rohan.. Grid is binding with empty record on page load.. but it is restricted when post back..
 
If Not (IsPostBack) Then
CreateEmptyCaseGrid()
End If
Rohan Leuva at 29-Apr-13 1:06am
   
Add your data to datatable and bind that datatable to gridview modifying your above code,keep (!IsPostBack) code as it is.
cyanceenu at 29-Apr-13 2:18am
   
there exists the problem... there is only one empty row in grid while post back pageload
Rohan Leuva at 29-Apr-13 3:23am
   
i am not getting you. i suggested you that first of all get user data into data table and from data table to gridview.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 85
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 29 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100