How to assign id zero while selecting the default in dropdownlist

I have a drop Down list and I want that if the user selected nothing the id should be stored in database as 0, other wise if the user selected something then the id of that item is stored.
Code is here:

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {

       Query = @"SELECT [category_id] FROM [Category_Master]";
       ds1 = dl.fetchrecord(Query);
       ddl_parent.Items.Insert(0, new ListItem("---none---"));
       int i = 0;
       while (i < ds1.Tables[0].Rows.Count)
       {
           flag = 1;
           catname = "";
           index = 1;
           ListItem li = new ListItem();
           li.Text = catmapping(ds1.Tables[0].Rows[i]["category_id"].ToString());
           li.Value = ds1.Tables[0].Rows[i]["category_id"].ToString();
           ddl_parent.Items.Add(li);
           i = i + 1;
    }
   }
   lbl_mess.Text = "";
}


protected void Button1_Click(object sender, EventArgs e)
{

   if (IsPostBack)
   {
       Query = @"INSERT INTO [RbmDatabase].[dbo].[Category_Master]
      ([Category_ParentId]
      ,[Category_Name]
      ,[Category_MetaTag]
      ,[Category_MetaTagKeywords]
      ,[Category_Description]
      ,[Category_SortOrder]
      ,[Category_Status]
      ,[Category_UpdateDate])
VALUES ('" + dl.QoutesHandel(ddl_parent.SelectedValue.ToString()) + "','" + dl.QoutesHandel(txt_category.Text.Trim()) + "','" + dl.QoutesHandel(txt_MTdesc.Text.Trim()) + "','" + dl.QoutesHandel(txt_MTkey.Text.Trim()) + "','" + dl.QoutesHandel(txt_Desc.Text.Trim()) + "','" + dl.QoutesHandel(txt_order.Text.Trim()) + "','" + dl.QoutesHandel(ddl_status.SelectedIndex.ToString()) + "','" + String.Format("{0:yyyy-MM-dd}", DateTime.Now) + "')";
       dl.insertrecord(Query, lbl_mess);
       lbl_mess.Text = "Record Inserted  Successfull.....!";

   }

}

  • Storing a file in a database as opposed to the file system?
  • Can DB2 and SQL Server be installed on the same machine?
  • Procedure to check annual date
  • SQL Server 2014 time outs while running backups
  • SQL Server Plans : difference between Index Scan / Index Seek
  • SSRS Total of IIF with SUM
  • Skip-over/ignore duplicate rows on insert
  • Len function on Float in SQLServer gives wrong length
  • Batch SQL Server Results by Max Number of Rows
  • incorrect syntax near the keyword 'Select'. for a balancecode
  • SQL Server Import wizard fails with incomprehensible message
  • How to get number of rows updated by a query in .net
  • One Solution collect form web for “How to assign id zero while selecting the default in dropdownlist”

    You should insert the “none” value when creating the list item

    new ListItem("---none---", "0"));
    
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.