"Ссылка на объект не установлена на экземпляр объекта". в griview
<pre>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"); //Label lblID = (Label)GridView2.Columns[0].FindControl("lblvID"); Label lblID = (Label)GridView2.FindControl("lblvID"); string voterID = lblID.Text; string studentId = lblStudentId.Text; // string id =; // string testing = this.Encrypt(id.Trim()); String query = "insert into voting (CandidateStudentID,voterStudentID,DateTime)values ('" + lblStudentId.Text + "','" + Session["UserName"].ToString() + "','" + time.ToString(format) + "')"; if (Session["UserName"].ToString().Equals(lblID.Text)) { Label1.Text = "You voted beofre"; } else { MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); MySqlCommand MyCommand2 = new MySqlCommand(query, MyConn2); MySqlDataReader MyReader2; MyConn2.Open(); MyReader2 = MyCommand2.ExecuteReader(); Label2.Text = "Thank you for You Vote"; } } <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" Font-Size="Medium"> <Columns> <asp:TemplateField HeaderText="Student ID"> <ItemTemplate> <asp:Label ID="lblvID" runat="server" Width="150px" Text='<%#Eval("voterStudentID") %>'/> </ItemTemplate>
Что я уже пробовал:
The link button belongs to gridview 1. I'm getting the Object reference not set to an instance of an object error message at line Label string voterID = lblID.Text; For girdview2, I'm only selected studentID from voting table.