Hi every One

I am using FormView which is bound to EntityDataSource (VS 2008).

It is working Correctly when I Add data manually

But I want to add Dropdownlist which is bounded to another table Its Selected Value should be inserted in Database (Orginal Table of EntityDatasource).

How I accomblish this task

Dear,

Your problem is to bind the DropdownList control instead of regular Text or Label control. Isn't it?

I have replaced textbox with Dropdownlist and also bind the dropdownlist with an other entitydatasource. Now my problem is that When I click the insert button, The selected value of Drpdownlist should also be save in db.

Don't forget to bind the DropDownList's selectedvalue property to the EntityDataSource.

Thanks
I have set. It is working
Problem is that When I insert data It through exception Primary Key Deos not allow null. Primary Key field is of GUID type. How I can provide a new GUID to Label Control in FormView

adatapost>Use the System.Guid class. The following code will help you.

SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=c:\csnet\sample1\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
        SqlCommand cmd = new SqlCommand("insert into emp values (@p1,@p2)", cn);
        cmd.Parameters.Add("@p1", SqlDbType.UniqueIdentifier, 32, "eno");
        cmd.Parameters.Add("@p2", SqlDbType.VarChar, 50, "ename");

        Guid g=Guid.NewGuid();

        cmd.Parameters[0].Value = g;  // GUID
        cmd.Parameters[1].Value = "R";

        cn.Open();
        cmd.ExecuteNonQuery();
        cn.Close();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.