我无法存储下拉列表中的值
本文关键字:下拉列表 存储 | 更新日期: 2023-09-27 18:18:08
这是我的代码,当我在浏览器中运行代码时,我无法将值存储到我从下拉
获得的数据库中我试了很多次但都失败了。有人能提出解决办法吗?
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>
EDIT:
你实际上甚至读locationSelectDrop的值在你的BranchAdminDetails数据对象?:)
每次当您单击提交按钮时, Page_Load将调用,并在您的代码中为每个post back加载事件再次填充您的下拉列表并将选定值设置为第0个位置。因此取消注释Page_Load事件中的IsPostback检查,并尝试再次调试