Click here to Skip to main content
15,944,397 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Textboxs in Gridview in each row i have to give the alert if any of Textbox will contain null values on save button click, save button if out of the gridview .

I have done in the following manner.
C#
function validate() {
    var flag = true;
    var gridview = document.getElementById('<%=grdprescript.ClientID %>'); //GridView1 is the id of ur gridview.
        
    var texts = new Array();
    
    for (var i = 0; i < texts.length; i++) {
        if (texts.items(i).value == '') //If dropdown has no selected value
        {
            flag = false;
            break; //break the loop as there is no need to check further.
        }
    }
    
    if (!flag) {
        alert('Please Enter Date in each text');
    }

    return flag;
}

Please help me friends thank in advance.
Posted
v3

Logic
On Save Button Click Event...

  • Loop through the GridViewRows
  • Find the particular Control (TextBox) inside the GridViewRow
  • Check is its value is null
  • Show one lable on each row saying TextBox value is null (showing alert for each row is not a good idea)
 
Share this answer
 
v2
Comments
viky.singh 28-Aug-13 10:35am    
thanks Tadit i have done in this way row.Cells[3].ClientID.Length == 0
Try this in Save button click

C#
foreach (DataGridViewRow row in dataGridView2.Rows)
           {
               if (row.Cells[0].Value == null)
               {
                   MessageBox.Show("Your Message here");
               }
           }


Cells[0] is grids first column you can use any column...
 
Share this answer
 
Comments
viky.singh 28-Aug-13 10:08am    
thanks maheshnakka but can you give solution in asp.net value is allowed in that.
viky.singh 28-Aug-13 23:24pm    
thans maheshnakka your idea works for me
maheshnakka 30-Aug-13 1:12am    
U r welcome .happy to help anytime
if (row.Cells[2].ClientID.text.tostring() == 0 || row.Cells[3].text.tostring()== 0 || row.Cells[1].ClientID=="0")
{
alert(); or lblerrormsg.text=" please enter date";
}
// 3 will for dropdownlist
 
Share this answer
 
v2

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