Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
Dropdownlist validation in Asp.net Using Required field validator

Dropdownlist validation in Asp.net Using Required field validator

Introduction:
Here I will explain how to Dropdownlist validation in Asp.net Using Required field validator.
In previous articles I explained validate email address using  code for validating checkbox in asp.net  In 
ASP.Net And Many Article Relating to Validation Now I Will   Explained  Dropdownlist validation in Asp.net Using RequiredField validator  In Asp.net.
To implement this one we need to write code as shown below in your aspx page
<asp:DropDownList  CssClass="dropdown" ValidationGroup="g1" 
ID="dropdown" runat="server" OnSelectedIndexChanged="dropdown_SelectedIndexChanged"></asp:DropDownList>
<asp:RequiredFieldValidator ControlToValidate="dropdown" ID="RequiredFieldValidator1"
ValidationGroup="g1" CssClass="dropdown" ErrorMessage="Select Dropdown"InitialValue="--Select Asprockers--" runat="server" Display="Dynamic">
</asp:RequiredFieldValidator>


dropdown.Items.Insert(0, "--Select Asprockers--"));
Code for Validating Checkbox in asp.net with required field validator

Code for Validating Checkbox in asp.net with required field validator

Above I have placed an ASP.Net Custom Validator besides the ASP.Net Checkbox control. For the ASP.Net Custom Validator I have specified the ClientValidationFunction property to a JavaScript function ValidateCheckBox which validates the whether the checkbox is checked or not.


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script type = "text/javascript">
function ValidateCheckBox(sender, args) {
if (document.getElementById("<%=CheckBox1.ClientID %>").checked == true) {
args.IsValid = true;
} else {
args.IsValid = false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" />
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required" ClientValidationFunction = "ValidateCheckBox"></asp:CustomValidator><br />
<asp:Button ID="Button1" runat="server" Text="Submit"/>
</form>
</body>
</html>
Get (Read) Connectionstring from App.Config File in C#

Get (Read) Connectionstring from App.Config File in C#



Introduction:

Here I will explain how to read or get connectionstring from app.config file in 
c#. By using System.Configuration reference we can read or get connectionstring from app.config file in windows or console application in c#.



<connectionStrings>
<add name="dbconnection" connectionString="DataSource=KaushikDhameliya;Initial Catalog=Kaushik;Integrated Security=true" providerName="System.Data.SqlClient" />
</connectionStrings>

string admin= ConfigurationManager.ConnectionStrings["admin"].ConnectionString;

Dynamically Dropdown bind Using C#

Dynamically Dropdown bind Using C#

In this example, I will show on how to Dynamically Dropdown Bind Using C# 


      
      
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();
        SqlCommand cmd = new SqlCommand("SELECT Email_Id, Id FROM Admin_Deposit WHERE           Status = '" + 1 +"'", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        DropDownList1.DataTextField = "Email_Id";
        DropDownList1.DataValueField = "Id";
        DropDownList1.DataSource = ds;

        DropDownList1.DataBind();

Generate Random Code In C#

Generate Random Code In C#


Generate Random Code In C#




private void generate()


    {


        var chars = "0123456789";


        var stringChars = new char[6];


        var random = new Random();




        for (int i = 0; i < stringChars.Length; i++)


        {


            stringChars[i] = chars[random.Next(chars.Length)];




        }




        var finalString = new String(stringChars);


        ab = finalString.ToString();


     //   lblOutlet_Code.Text = finalString.ToString();


    }





Popular Posts