![ישן](https://static.fresh.co.il/images/vBulletin/statusicon/post_old.gif)
12-10-2006, 10:58
|
|
|
חבר מתאריך: 12.09.06
הודעות: 11
|
|
Fill ListBox
למישהו יש קוד שממלא list box בנתונים מ data base ?
משהו כזה אבל לlist box ולא ל drop down list ?
publicvoid FillDropDownList (string strQ, string TextFieldName,string ValueFieldName, DropDownList DDL)
{
string QueryString;
DataReader=null;
QueryString=strQ;
Command=new SqlCommand(QueryString,Connection);
try
{
Command.Connection.Open(); //open Datareader
DataReader=Command.ExecuteReader(); //read from DB and put results in DataReader
DDL.DataSource=DataReader;
DDL.DataMember="Table1";
DDL.DataTextField=TextFieldName; //set textfield
DDL.DataValueField=ValueFieldName; //set valuefield
DDL.DataBind();
}
catch (Exception e) //catch exception
{
string s=e.Message; //send exception error message
}
finally
{
if (DataReader!=null) //close datareader
DataReader.Close();
Command.Connection.Close();
}
}
|