hi,
I want to capture all the rows data which displaying in a gridview without selecting the gridview.Like
string []str=new string[30];
for(int i=0;i { str[i]=((Label)GridView1.Rows[i].FindControl("Label7")).ToString(); ////But this gives error }
Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable
to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to
cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast
object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object
of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of
type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of type
'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label'
to type 'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label' to
type 'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label' to type
'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable
to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to
cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast
object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object
of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of
type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of type
'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label'
to type 'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label' to
type 'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label' to type
'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable
to cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to
cast object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast
object of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object
of type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of
type 'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of type
'System.Web.UI.WebControls.Label' to type 'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label'
to type 'System.IConvertible'.Unable to cast object of type 'System.Web.UI.WebControls.Label' to
type 'System.IConvertible'.Unable to cast object of type /////////system.web.ui.webcontrols.Label to type system.iconvertible
Have a look at this link, http://forums.asp.net/t/1219338.aspx/1
I guess
str[i]=((Label)GridView1.Rows[i].FindControl("Label7")).Text;Use lbl.Text instead lbl.ToString()
i think you are trying to convert a Label object to string, which is not valid, try some thing like this,
str[i]=((Label)GridView1.Rows[i].FindControl("Label7")).Text;Just be aware that you will only be able to access the value for Label7 for the number of rows that are displayed in the Gridview, so if you have paging on, you can only access the data for the current page. Can you access the source of the GridView's data?
This may be a better method.
沒有留言:
張貼留言