它与绑定数据列表有关 [英] its related to binding datalist
问题描述
ad = new SqlDataAdapter("select * from posted_data where 1=1" + query, c.con);
dt = new DataTable();
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
string[,] arr=new string[dt.Rows.Count,dt.Columns.Count];
for (int i = 0; i <= dt.Rows.Count; i++)
{
for (int j = 0; j <= dt.Columns.Count; j++)
{
arr[i,j] = dt.Rows[i][j].ToString();
for (int k = 0; k <= arr[i,j].Length; i++)
{
if ((arr[i,j] == ""))
{
arr[i,j] = "Not Applicabel";
DataList1.DataSource =arr[i,j];
DataList1.DataBind();
}
else
{
DataList1.DataSource = arr[i,j];
DataList1.DataBind();
}
}
//if (dt.Rows[i][j].ToString() == "")
// {
// str = "NA";
// }
//else
//{
//str=dt.Rows[i][j].ToString();
//}
}
}
}
else
ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "alert('Data not found'); window.location.href='Index.aspx';", true);
}
先生,我使用此代码绑定字符串类型数组,但显示错误
即DataBinding:``System.Char''不包含名称为``UserId''的属性.
在这条线上,即
DataList1.DataBind();
...
sir i m using this code for binding string type array but its showing error
i.e. DataBinding: ''System.Char'' does not contain a property with the name ''UserId''.
on this line i.e.
DataList1.DataBind();
how can i solved it help me plz....
推荐答案
您已将数据表与数据一起归档,然后为何尝试使用字符串数组来绑定数据. .
要将数据绑定到数据列表,请使用此方法....
You have data table filed with your data then why you trying to use string array for binding data...
For binding data to data-list just use this....
DataList1.DataSource =dt;
DataList1.DataBind();
还有你写的SQL查询我无法忍受的....
and also what you write a sql query i cant under stand....
ad = new SqlDataAdapter("select * from posted_data where 1=1" + query, c.con);
是什么意思...
从* 1中的postd_data中选择*" +查询
什么是查询"
what is mean by...
"select * from posted_data where 1=1" + query
what is "query"
and binding wd array bcoz if datatable contain any column with null value then null value is replace by "na" and print on label
为此,您必须注意称为DataList1_ItemDataBound
的数据列表事件中的空值.
并且在该事件内,您必须编写代码以检查空值并分配一个由用户定义的,代表空值的值...
为了检查值,您需要像这样转换您的事件参数...
for this you have to take care for null value inside a datalist event called DataList1_ItemDataBound
and inside that event you have to write your code for checking null value and assigning a user defined value instaed of null value...
for checking value you need to cast your event argument like this...
((System.Data.DataRowView)e.Item.DataItem)["YOUR COLUM NAME"].toString();
使用此值检查是否为空,并将其替换为用户定义的值,例如"N/A"
一切都在侧面DataList1_ItemDataBound
中完成,这是执行此操作的正确方法....
use this value to check for null and replace it with user defined value like "N/A"
its all done in side DataList1_ItemDataBound
that''s the right way for doing this....
确保您的代码并检查出"UserId"数据类型或dbtype .
您在SQL查询/函数或存储过程中的哪里使用"UserId".
全部检查:
for(int i = 0; i< = dt.Rows.Count; i ++)
我认为需要更改:
for(int i = 0; i< dt.Rows.Count; i ++)
Bcoz,最后一行的索引应该为null,这可能会造成问题!
Make sure about your code and check it out ''UserId'' datatype or dbtype.
Where are you using ''UserId'' in SQL Query/function or Stored procedure.
Check it all:
for (int i = 0; i <= dt.Rows.Count; i++)
I think need to change:
for (int i = 0; i < dt.Rows.Count; i++)
Bcoz, at the last row index should be null,that may be create a problem!
这篇关于它与绑定数据列表有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!