急 文章分页
我举个例子
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
string strTemp = "a//b//c//d//e ";
ArrayList returnList = new ArrayList();
returnList.Add(strTemp.Substring( 0, strTemp.IndexOf( "// ")) );
strTemp = strTemp.Substring(strTemp.IndexOf( "// ") + 2);
ArrayList al = SplitByString(strTemp);
DataTable dt=null;
dt.Columns.Add( "content ");
DataRow dr=null ;
dr[ "content "]=al;
dt.Rows.Add(dr);
}
}
public ArrayList SplitByString( string strTemp)
{
ArrayList returnList = new ArrayList();
//ArrayList tempList = SplitByString(strTemp);
foreach(string strSplit in returnList)
{
returnList.Add(strSplit);
}
return returnList;
}
有的目标是显示在table中
a
b
c
d
e
帮我看看那里错了,谢谢
[解决办法]
string strTemp = "a//b//c//d//e ";
char[] cArr = "// ".ToCharArray();
string[] arr = strTemp.Split(cArr);
DataTable dt = new DataTable();
dt.Columns.Add( "content ", typeof(string));
for (int ix = 0; ix < arr.Length; ix+=2)
{
dt.Rows.Add(new object[] { arr[ix] });
}
[解决办法]
报错是因为dt,dr 都没有实例化.
[解决办法]
if (!IsPostBack) { string strTemp = "a//b//c//d//e "; string[] ary = System.Text.RegularExpressions.Regex.Split(strTemp, "// "); DataTable dt = new DataTable(); dt.Columns.Add( "content "); for (int i = 0; i < ary.Length; i++) { dt.Rows.Add(ary[i]); } DataGrid dg = new DataGrid(); dg.DataSource = dt.DefaultView; dg.DataBind(); this.panel1.Controls.Add(dg); }
[解决办法]
up
cpp2017(慕白兄)
[解决办法]
string[] ary = System.Text.RegularExpressions.Regex.Split(strTemp, "// ");
呵呵 ^_^ 这个不错
[解决办法]
DataRow dr 整个DR应该是:dr=dt.NewRow();
[解决办法]
算了,都说完了
[解决办法]
佩服Lz