Find the value in gridview using findcontrol and comapre it with data in database

protected void LinkButton_Click(Object sender, EventArgs e) { String MyConnection2 = "Server=localhost;database=ovs;Uid=root;password=; Convert Zero Datetime=True"; DateTime time = DateTime.Now; // Use current time string format = "yyyy-MM-dd HH:mm:ss"; string UserName4 = HttpContext.Current.User.Identity.Name; GridViewRow grdrow = (GridViewRow)((LinkButton)sender).NamingContainer; Label lblStudentId = (Label)grdrow.Cells[0].FindControl("lblID"); string studentId = lblStudentId.Text; String query = "insert into voting (CandidateStudentID,voterStudentID,DateTime)values ('" + lblStudentId.Text + "','" … Read more

C#, FindControl

I’m sorry, but I can’t understand why this doesn’t work. After compile, I receive a “Null reference exception”. Please help. public partial class labs_test : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text != "") { Label Label1 = (Label)Master.FindControl("Label1"); Label1.Text = "<b>The text you entered was: " + TextBox1.Text + ".</b>"; … Read more

ASP.NET Is there a better way to find controls that are within other controls?

I currently have a dropdown inside an ascx control. I need to “find” it from within the code behind on another ascx that is on the same page. It’s value is used as a param to an ObjectDataSource on ascx #2. I am currently using this ugly piece of code. It works but I realize if the conrtol order were to change or various other things, it wouldn’t be where I am expecting. Does anyone have any advice how I should properly be doing this?