I use linq bind data to gridview, code behide that:
C#
publicpartialclassWebForm1 : System.Web.UI.Page
{
DataContext sqlContext = new DataContext();
protectedvoidPage_Load(object sender, EventArgs e)
{
var _Agent = from c in sqlContext.Agents
select c;
GridView1.DataSource = _Agent;
GridView1.DataBind();
}
protectedvoidGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView dRowView = (DataRowView)e.Row.DataItem;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
RadioButtonList _rblGender = (RadioButtonList)e.Row.FindControl("rblGender");
_rblGender.SelectedValue = dRowView[3].ToString();
}
}
}
}
I can't get value from gridview. It return error:
Unable to cast object of type
'<>f__AnonymousType0`11[System.Int32,System.String,System.String,
System.String,System.String,System.String,System.String,System.Nullable`1[System.DateTime],
System.String,System.String,System.String]'
to type 'System.Data.DataRowView'.
Code
CSS
Line28: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
Line 29: {
Line30: DataRowView dRowView = (DataRowView)e.Row.DataItem;
Line31: if (e.Row.RowType == DataControlRowType.DataRow)
Line 32: {
Please help me!
Thanks
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Lalit MRank #1,186 · 1.5K reputationPosted Dec 2, 2009, 7:51 PM EST
Lalit MRank #1,186 · 1.5K reputationPosted Dec 2, 2009, 7:51 PM EST