Thank you all for Answers & Suggestions,
But, I also want to share one more Answer of my question, which I found at other Asp Forum, If any one also have to face that problem or beginner to Asp follow that Answer,
First Create a Method for filling DropDownList:
private void FillCatagoryList()
{
try
{
SqlConnection sqlcon = new SqlConnection (ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
sqlcon.Open();
DataSet ds = new DataSet();
SqlCommand cmd = new SqlCommand("select * from catagories", sqlcon);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds);
List_Catagories.DataSource = ds;
List_Catagories.DataTextField = "cat_name";
List_Catagories.DataValueField = "cat_id";
List_Catagories.DataBind();
}
catch (Exception err)
{
lblResults.Text = "Error reading list of names. ";
lblResults.Text += err.Message;
}
finally
{
sqlcon.Close();
}
Previous Code will save temprory both Category Id & Category Name, and shows Category Name in "DropDownList" from "List_Catagories.DataTextField" and save "Cat_id" in "List_Catagories.DataValueField".
Then Save the New Sub-Category Item(User Input) and its code(From DropDownList Selected Item) using the following code:
try
{
SqlConnection sqlcon = new SqlConnection (ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
sqlcon.Open();
string nam = txtSubCategory.Text.Trim();
int Sel_id = Convert.ToInt32(List_Catagories.SelectedValue);
SqlCommand cmd = new SqlCommand("INSERT INTO catagories_sub (category_id, Category_Name) values ("+ Sel_id +", '"+ nam +"')", sqlcon);
cmd.ExecuteNonQuery();
}
catch (Exception err)
{
lblResults.Text = "Error reading list of names. ";
lblResults.Text += err.Message;
}
finally
{
sqlcon.Close();
}
So, That's the Solution, and it will save a Category id of Category table to the sub category, if we select through inner join, the result will give us the category and sub-category matched record, I am pasting my SQL Query so you can execute it easiy,
select cat_name, sub_name from category c inner join sub_category sc on c.cate_id = sc.cate_id
Thanks,
Regards,
Mustafa Iqbal.