Paging DataGrid and e.Item.FindControl

shahab

Junior Contributor
Joined
Aug 14, 2003
Messages
206
Location
Iran(Middle East)
I have a DataGrid(Pagable one) that there is a dropdownlist in it.Ok
Scenario : When ever the dropdownlist value selected specia operation must happen.
Problem : in newPageIndexes i recieve this error :
C#:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
 
Source Error: 
Line 174:                if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "edit")
Line 175:                {
Line 176:                    Response.Redirect("EditNews.aspx");
Q1-Is it true to using DataGrid1_ItemCommand for :
if (((DropDownList)e.Item.FindControl("DropDownList1")).SelectedValue == "edit") ??? :rolleyes: :rolleyes: :confused:
*****************************************************
Q2-The DataGrid1_PageIndexChanged is this:
C#:
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
        {
            DataGrid1.CurrentPageIndex=e.NewPageIndex;
            bindGrid1();
 
            /*try
            {
                if ((DataGrid1.PageCount - e.NewPageIndex) > 0)
                {
                    DataGrid1.CurrentPageIndex=e.NewPageIndex;
                    //Session["NewsId"]=DataGrid1.DataKeys[0];
                    bindGrid1();
                }
            }
            catch (Exception e01)
            {
                Label3.Text = e01.Message.ToString();
            }*/
        }
Is that enough? :-\
*******************************************************
Q3-What about the error?(Object not set ...)
Help me! :(

[edit]Changed PHP tags to CS tags:Robby[/edit]
 
Last edited by a moderator:
the "FindControl" method brings back just a "general" object, it has no idea that it's a dropdown list...

you have to cast it to a dropdownlist first.. THEN you can get the value :)
 
Back
Top