从数据库中读出一个dataset
listBox1.DataSource = DS.Tables[0];
listBox1.DisplayMember = "column1";
请问怎么获取listbox1中选中项?为什么我用textBox1.Text = listBox1.SelectedItem.ToString();显示出来的是 “System.Data.DataRowView”这句莫名的话。。dataset里没有这个
listBox1.DataSource = DS.Tables[0];
listBox1.DisplayMember = "column1";
请问怎么获取listbox1中选中项?为什么我用textBox1.Text = listBox1.SelectedItem.ToString();显示出来的是 “System.Data.DataRowView”这句莫名的话。。dataset里没有这个
textBox1.Text = (listBox1.SelectedItem as DataRow)["column1"].ToString();
Textbox1.Text = (listBox1.SelectedItem as DataRowView).Row["column1"].ToString();
{
DataTable table = new DataTable();
table.Columns.Add("column1", typeof(int));
table.Columns.Add("column2", typeof(string));
DataRow row = table.NewRow();
row[0] = 10;
row[1] = 15;
table.Rows.Add(row);
listBox1.DataSource = table;
listBox1.DisplayMember = "column1";
}private void button1_Click(object sender, EventArgs e)
{
Text = (listBox1.SelectedItem as DataRowView).Row["column1"].ToString();
}
测试通过。
<asp:ListBox ID="lstFather" runat="server" Width="125px" Rows="1"
DataSourceID="FatherDataSource" DataTextField="TypeName"
DataValueField="TypeID"></asp:ListBox>
<asp:ObjectDataSource ID="FatherDataSource" runat="server"
SelectMethod="GetFatherList" TypeName="SNS.DAL.CowryType">
</asp:ObjectDataSource>
textBox1.Text = listBox1.SelectedItem.ToString();是什么时候用
this.listBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.dataSet1, "Table1.Column4", true));
this.listBox1.DataSource = this.dataSet1;
this.listBox1.DisplayMember = "Table1.Column1";
this.listBox1.FormattingEnabled = true;
this.listBox1.Name = "listBox1";
this.listBox1.ValueMember = "Table1.Column2";
listBox1.SelectedItem.Value
。