Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi there;
I have a user control which I've used a DataGrid on it. I wanna find control on it so I have an ItemCommand event with following code:

if (e.CommandName == "Edit")
            {
                pnlUpdate.Visible = true;
                pnlDelete.Visible = false;
                string Code = e.Item.FindControl("base_NationalCode").ToString();
            }


when I run the project I become with this error
Quote:
Object reference not set to an instance of an object

would you please help me in solving this problem;
Thank you in advance

What I have tried:

- - - -
Posted
Updated 27-May-20 22:17pm

1 solution

If you know the column index, you can try:
C#
string Code = e.Row.Cells[index].Text.ToString()

or:
C#
YourControlType yc = (YourControlType)e.Row.FindControl("base_NationalCode");
string Code = string.Empty;
if(yc!=null) Code = yc.ToString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900