后台代码如下:string sql_string = "select * from Notice where Id=" + Id.ToString ();
string[] K_text ={ TB_Title.Text, TB_Author.Text, FCK_Content.Value, TB_Time.Text, TB_Class.Text, TB_IsPub.Text, TB_State.Text };
datahelper datahelp = new datahelper();
datahelp.getdata(sql_string, K_text);
datahelp.getdata(sql_string ,K_text );
这是datahelper类中的方法:
public void getdata(string sql_string,string []K_text)
{
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myAdap = new SqlDataAdapter(sql_string, sqlcon);
DataSet myds = new DataSet();
myAdap.Fill(myds, "Notice");
for (int i = 0; i < K_text.Length; i++)
{
K_text[i] = myds.Tables ["Notice"].Rows[0][i].ToString ();
}
}
结果只是把数据赋值到数组而已,控件上没有显示,请问如何在保留数组的情况下在控件上显示? 难道要一个一个的赋值?
string[] K_text ={ TB_Title.Text, TB_Author.Text, FCK_Content.Value, TB_Time.Text, TB_Class.Text, TB_IsPub.Text, TB_State.Text };
datahelper datahelp = new datahelper();
datahelp.getdata(sql_string, K_text);
datahelp.getdata(sql_string ,K_text );
这是datahelper类中的方法:
public void getdata(string sql_string,string []K_text)
{
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myAdap = new SqlDataAdapter(sql_string, sqlcon);
DataSet myds = new DataSet();
myAdap.Fill(myds, "Notice");
for (int i = 0; i < K_text.Length; i++)
{
K_text[i] = myds.Tables ["Notice"].Rows[0][i].ToString ();
}
}
结果只是把数据赋值到数组而已,控件上没有显示,请问如何在保留数组的情况下在控件上显示? 难道要一个一个的赋值?
{
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myAdap = new SqlDataAdapter(sql_string, sqlcon);
DataSet myds = new DataSet();
myAdap.Fill(myds, "Notice");
int count=0;
count=myds.Tables["Notice"].Rows.count
string []K_text=new string[count];
for (int i = 0; i < count; i++)
{
K_text[i] = myds.Tables ["Notice"].Rows[0][i].ToString ();
}
return K_text;
}
后台:
datahelper datahelp = new datahelper();
string[] K_text =datahelp.getdata(sql_string, K_text);
然后TB_Title.Text=K_text[0];如此如此
ref string []K_text
你可以用repeater或者datalist等绑定,在repeater或者datalist中加一个Text或者lable标签,
然后前台绑定字符串,后台像绑定数据集一样绑定一下数组就可以了