Thursday, 1 May 2014

Showing error if value entered in gridview is greater than required

No comments
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int lbl = 0;
        int txt = 0;
        Label l1 = (Label)GridView1.Rows[e.RowIndex].FindControl("lbl");
        TextBox tx = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt");
        lbl = int.Parse(l1.Text);
        txt = int.Parse(tx.Text);
        if (txt > lbl)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert('value is greater')", true);

        }
        else
        {
            lbl = txt;
        }
               
    }