C# 我无法存储下拉列表中的值

C# 我无法存储下拉列表中的值,c#,asp.net,C#,Asp.net,这是我的代码,当我在浏览器中运行代码时,我无法将值存储到从下拉列表中获取的数据库中 我试了很多次,但都失败了。有人能提出解决办法吗 public partial class UserBranchAdminProfile : System.Web.UI.Page { public BLLCreateUser blbranchAdmin = new BLLCreateUser(); public Branch branchdetails = new Branch(); p

这是我的代码,当我在浏览器中运行代码时,我无法将值存储到从下拉列表中获取的数据库中

我试了很多次,但都失败了。有人能提出解决办法吗

public partial class UserBranchAdminProfile : System.Web.UI.Page
{  
    public BLLCreateUser blbranchAdmin = new BLLCreateUser();
    public Branch branchdetails = new Branch();
    public BranchAdminDetails branchProfileDetails = new BranchAdminDetails();
}  

protected void Page_Load(object sender, EventArgs e)
{
    // if (!IsPostBack)
    {
        locationSelectDrop.DataSource = blbranchAdmin.getAllBranches();
        locationSelectDrop.DataTextField = "BranchLocation";
        locationSelectDrop.DataValueField = "BranchId";
        locationSelectDrop.DataBind();
    }
}

protected void submitProfileButton_Click(object sender, EventArgs e)
{
     branchProfileDetails.userId = userIdText.Text;
     branchProfileDetails.branchLocation=locationSelectDrop.SelectedValue.ToString();                        
     branchProfileDetails.address = addressTextBox.Text;
     branchProfileDetails.phoneNo = phoneNoText.Text;
     branchProfileDetails.emailId = emailText.Text;
     BLLCreateUser bc = new BLLCreateUser();

     bool result = bc.insertBranchAdminProfileDetails(branchProfileDetails);

     if (result == true)
     {
         branchAdminProfileLabel.Visible = true;
     }
}
这是我的html标记:

<td class="style1"> 
    <asp:Label ID="locationSelect" runat="server" Text="Enter Location"/>       
</td>
<td class="style2">
    <asp:DropDownList ID="locationSelectDrop" runat="server" style="marginleft:0px" 
            Width="178px"></asp:DropDownList>
</td>
编辑:


您是否真的在BranchAdminDetails数据对象中读取locationSelectDrop的值

每次单击“提交”按钮时,页面加载将调用,并在每次回发加载事件的代码中再次填充下拉列表,并将所选值设置为第0个位置。因此,在Page_Load事件中取消对IsPostback检查的注释,并再次尝试调试。

尝试获取值时是否出现异常?否,但当我检查数据库0是否已存储时,是否可以向我们显示到数据库的连接字符串?数据源=PC251181\SQLEXPRESS;初始目录=VRS_测试;Integrated Security=true我检查我的数据库时它仍然不工作它仍然是零编辑我的答案,我没有看到你在发布的代码中的任何地方填充数据对象中的位置,你错过了吗?