C# BLL中的填充下拉框
如何填写数据库中的下拉列表?我有UI和BLL层和sp,但无法填充它。下拉名称为DRPDWnComplinantTypes。这类事情我做过很多次,但这次没有。请帮忙C# BLL中的填充下拉框,c#,asp.net,sql,C#,Asp.net,Sql,如何填写数据库中的下拉列表?我有UI和BLL层和sp,但无法填充它。下拉名称为DRPDWnComplinantTypes。这类事情我做过很多次,但这次没有。请帮忙 protected void btnSave_Click(object sender, EventArgs e) { try { ComplainantBizz comBizz = new ComplainantBizz(txtName.Text, txtCNIC.Tex
protected void btnSave_Click(object sender, EventArgs e)
{
try
{
ComplainantBizz comBizz = new ComplainantBizz(txtName.Text, txtCNIC.Text, txtAddress.Text, txtContact.Text, Convert.ToInt32(DropdwnCompType.SelectedValue));
ManageComplainant mngComplainantType = new ManageComplainant();
bool Result = mngComplainantType.Insert(comBizz);
if (Result == true)
{
HiddenFieldSetMessage.Value = "Saved";
HiddenFieldShowMessage.Value = "True";
Clear(txtName);
}
else
{
HiddenFieldSetMessage.Value = "RecordAlreadyExists";
HiddenFieldShowMessage.Value = "True";
}
}
catch (Exception)
{
HiddenFieldSetMessage.Value = "NotSaved";
HiddenFieldShowMessage.Value = "True";
}
}
BLL:
SP:
这是我正在呼叫的SP
alter PROCEDURE SelectAllComplainantTypes_SP
AS
BEGIN
Begin Try
Select * from ComplainantTypes
End Try
Begin Catch
Select ERROR_MESSAGE() as ErrorMsg
End Catch
END
GO
您需要将datatable return从函数绑定到dropdownlist,如中所示
dropdonlist.datasource=FillDropDown();
dropdownlist.datatextfield="yourTextColum";//in example column name "City"
dropdownlist.dataValueFiedl="yourValueColumn";//in example cloum name "ID"
dropdownlist.databind();
就这些
注意:如果您将从函数返回null,则会引发异常,如果未返回任何数据,则dropdownlist中不会显示任何数据
dropdonlist.datasource=FillDropDown();
dropdownlist.datatextfield="yourTextColum";//in example column name "City"
dropdownlist.dataValueFiedl="yourValueColumn";//in example cloum name "ID"
dropdownlist.databind();