如何将DDL的DataValueField作为Int32传递给formviewupdate SQL语句

本文关键字:formviewupdate 语句 SQL Int32 作为 DDL DataValueField | 更新日期: 2023-09-27 18:15:50

下面的代码导致错误:

不能隐式地将Int类型转换为String。

问题在这里:Convert.ToInt32(priorityLanguage_DDL.DataValueField);我想知道为什么!

protected void UpdateButton_click(object sender, EventArgs e)
{   
    DropDownList priorityLanguage_DDL = FormView3.FindControl("priorityLanguage_DDL") as DropDownList;
    SqlDataSource_membersDetails.UpdateParameters["priorityLanguage_ddl_par"].Type = TypeCode.Int32;
    SqlDataSource_membersDetails.UpdateParameters["priorityLanguage_ddl_par"].DefaultValue = Convert.ToInt32(priorityLanguage_DDL.DataValueField);
}

更新

正确的答案是替换priorityLanguage_DDL。DataValueField with priorityLanguage_DDL.SelectedValue....

如何将DDL的DataValueField作为Int32传递给formviewupdate SQL语句

因为DefaultValue属性是string,而您正在尝试传递int