这是我的代码,当我在浏览器中运行代码时,我无法将值存储到我从下拉列表中获取的数据
我尝试了很多次却失败了。有人可以建议修复吗?
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>
答案 0 :(得分:0)
编辑:
您实际上是否在BranchAdminDetails数据对象中读取了locationSelectDrop的值? :)
答案 1 :(得分:0)
每当您点击提交按钮时, Page_Load 将会调用,并在您的代码中为每个帖子重新加载事件再次填充您的下拉菜单并将所选值设置为第0个位置。所以在 Page_Load 事件中取消对IsPostback的检查,并尝试重新调试。