本文介绍了列表框显示system.data.datarowview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
列表框显示System.Data.DataRowView而不是实际值。
我尝试过:
listbox show System.Data.DataRowView instead of real values.
What I have tried:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
/* if (DropDownList1.SelectedValue == DropDownList1.SelectedItem.Text)
{
string query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME="+ "DropDownList1.SelectedItem.Text+" ;
DataTable dt = _Default.ExecuteQuery(query);
ListBox1.Items.Clear();
ListBox1.DataSource = dt;
ListBox1.DataBind();
}*/
string query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='" + DropDownList1.SelectedItem.Text+"'";
using (SqlCommand cmd = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds);
ListBox1.DataSource = ds.Tables[0];
ListBox1.DataBind();
}
}
}
推荐答案
这篇关于列表框显示system.data.datarowview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!