Click here to Skip to main content
15,900,254 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void griddistrict_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    if (((DropDownList)(griddistrict.Rows[e.RowIndex].FindControl("editdrp"))).SelectedValue == "select")
    {
        //string msg = @"<script language='javascript' type='text/javascript'>alert('Please Select State !')</script>";
        //Page.RegisterStartupScript("msg", msg);
        ClientScript.RegisterStartupScript(typeof(Page), "alert", "<script language='javascript'>alert('Please Select State !');</script>");
    }
    else
    {
        objda.Stateid = Convert.ToInt32(((DropDownList)(griddistrict.Rows[e.RowIndex].FindControl("editdrp"))).SelectedValue.ToString());
        objda.nid = Convert.ToInt32(griddistrict.DataKeys[e.RowIndex].Value.ToString());
        objda.district = ((TextBox)(griddistrict.Rows[e.RowIndex].FindControl("EditdistName"))).Text;
        objda.code = ((TextBox)(griddistrict.Rows[e.RowIndex].FindControl("Editdistcode"))).Text;
        objda.modifidate = DateTime.Now.ToString("D");
        objda.Modifyby = Session["username"].ToString();
        objda.updatedist();
        try
        {
            string strHostName = System.Net.Dns.GetHostName();
            string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
            objda.Ipaddress = clientIPAddress;
            objda.loginid = Session["username"].ToString();
            objda.description = "update   The Record   of nid  " + Convert.ToInt32(griddistrict.DataKeys[e.RowIndex].Value.ToString()) + "  in Table District Master Table";
            objda.insertlog();
        }
        catch
        {
        }
        griddistrict.EditIndex = -1;
        bindgrid();
    }
}





code is executed successfully

i see using brack point.

script is also executed but not show to client
Posted

1 solution

VinodKumar01 wrote:
if (((DropDownList)(griddistrict.Rows[e.RowIndex].FindControl("editdrp"))).SelectedValue == "select")


Basically Dropdownlist contains two properties DataTextField(For Name type) & DataValueField(For ID type) regarding Databind. I suspect "select" is DataTextField as per your code.

So your code should be

if (((DropDownList)(griddistrict.Rows[e.RowIndex].FindControl("editdrp"))).SelectedText == "select")

or
if (((DropDownList)(griddistrict.Rows[e.RowIndex].FindControl("editdrp"))).SelectedValue == 0)//Replace the 0 with your value

Why don't you try validators for controls? Try these
Link 1[^]
Link 2[^]
 
Share this answer
 

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