Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
When I click on the select for a particular row in grid view it should display the panel for me to reply the feedback. But there is no action.
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Net;
using System.Net.Mail;

namespace PS
{
    public partial class AdminHome : System.Web.UI.Page
    {
        public SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Bala\MyStuffs\system\PS\PS\App_Data\Database1.mdf;Integrated Security=True;User Instance=True");

        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        
        protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)
        {

            GridViewRow row = GridView1.SelectedRow;
            lblFeedbackNo.Text = row.Cells[1].Text;
            txtComment.Text = row.Cells[2].Text;
            Panel1.Visible = true;
            GridView1.Visible = false;


        }
       

        

        

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
          
	        string aTo = null;
	        string aFrom = "ps_fyp@outlook.com";
	        string aSubject = "WPEHMS Reply Message";
	        string aMsg = "Dear Student," + Environment.NewLine + txtReply.Text + Environment.NewLine + Environment.NewLine + Environment.NewLine + "Regards, " + Environment.NewLine + "WPEHMS";
	if (string.IsNullOrEmpty(txtReply.Text)) {
		lblValidation.Visible = true;

	} else {
		//------------------------------------------------------ Get email from database -------------------------------------------------------
        SqlCommand cmd = new SqlCommand("SELECT fdk_Email From tblFeedback Where fdk_No ='" + lblFeedbackNo.Text + "'",cn);
		cn.Open();
       
        aTo=(string)cmd.ExecuteScalar();
        cn.Close();
        


		//------------------------------------------------- Email service (hotmail) -------------------------------------------------------------
		string mMailServer = "smtp.live.com";
		//this is the name of mail server that email is sent to
		int mPort = 587;
		//port of mail server "use a value of 0 if none need be specified

		MailMessage message = new MailMessage();
		message.From = new MailAddress(aFrom);
		message.Subject = aSubject;
		message.Body = aMsg;
		message.To.Add(aTo);
		message.IsBodyHtml = false;
		message.Priority = MailPriority.Normal;

		SmtpClient oSMTP = new SmtpClient(mMailServer, mPort);
		// creates instance of mail client
		var _with1 = oSMTP;
		_with1.EnableSsl = true;
		_with1.DeliveryMethod = SmtpDeliveryMethod.Network;
		_with1.Credentials = new NetworkCredential("ps_fyp@outlook.com", "Thepassword");

		try {
			oSMTP.Send(message);
		} catch (Exception ex) {
        System.Windows.Forms.MessageBox.Show(ex.Message);
		}

		//
		//------------------------------------------------ Store replied data into database -----------------------------------------------------
		//string theStatus = "Replied";
        SqlCommand cmd1 = new SqlCommand("UPDATE  tblFeedback " + "SET staff_ID = '" + Session["idcode"] + "', fdk_Reply= '" + txtReply.Text + "'  WHERE fdk_No = '" + lblFeedbackNo.Text + "'",cn);
		
		cn.Open();
		cmd1.ExecuteNonQuery();
		cn.Close();
        System.Windows.Forms.MessageBox.Show("Reply Sent Successful");
		Panel1.Visible = false;
		GridView1.DataBind();
		GridView1.Visible = true;
	}
}
        

        
    }
}
Posted
Updated 18-Dec-14 16:50pm
v2
Comments
Member 11308948 18-Dec-14 23:36pm    
any solution
Thanks7872 19-Dec-14 1:45am    
Use debugger and see what is happening.

1 solution

first comform that the event 'GridView1_SelectedIndexChanged' is added in the aspx grideview control and the grideviews autopostpack = true . some time i miss this thinks only the event can't fire.
 
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