gridview on row data bound

R8VI
R8VI used Ask the Experts™
on
Hi i have the line of code below but have an error non-onvocable member.

Please help

Thanks,

R8VI
mysds.SelectParameters[0].DefaultValue =e.Row.DataItem("VD");

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
can you give more detail on your code? can you give us a whole function/sub or how do you put the line in code?

Author

Commented:
sure basically, i am using a nested gridview and want to get the vid from a grid called outsidegrid and pass into into the inside grid called insidegrid in the selectparameters. the whole function is as follows

hope that help

Thanks,

R8vi
protected void gridviewoutside_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            SqlDataSource mysds = (SqlDataSource)FindControl("SqlDataSource7");

            mysds.SelectParameters[0].DefaultValue = e.Row.DataItemIndex("VID");
                
        }

    }

Open in new window

Use DataItem.Eval() method to get value of VID column of current row in grid view. First parameter is current row's DataItem object and the second parameter is the column name.
Error raised because, e.Row.DataItemIndex is an object and not a Method to call and pass column name to get value. So Use following sample code:

protected void gridviewoutside_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
        if (e.Row.RowType == DataControlRowType.DataRow) 
        { 
            SqlDataSource mysds = (SqlDataSource)FindControl("SqlDataSource7"); 
 
            mysds.SelectParameters[0].DefaultValue = DataBinder.Eval(e.Row.DataItem, "VID"); 
                 
        } 
 
    }

Open in new window

Commented:
can you try e.Row.Cells[1].Text  or e.Row.Cells[1].value instead "e.Row.DataItemIndex("VID")
' not sure what column position of VID, i just put [1], you can change it.  
hope it helps

protected void gridviewoutside_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            SqlDataSource mysds = (SqlDataSource)FindControl("SqlDataSource7");

            mysds.SelectParameters[0].DefaultValue =e.Row.Cells[1].Text ;
               
        }

    }

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial