i create tow web page one that has dynamic crest for link-button in repeater and each link button it name is based on name for record stored in column name in database if new data insert into that table in data base on my web page dynamically creat new link-button it is name like the name that stored in data base
When click on link button I want retrieve all information for that name
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Messaging;
using System.Net;
using System.Net.Mail;
namespace exam
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["seniorConnectionString"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("select*from dbo.[Suporvisor(commtiee)]", con);
Page v = (Page)Context.Handler;
SqlDataReader dr;
dr = com.ExecuteReader();
if (dr.HasRows == true)
{
dr.Read();
Label1.Text = dr["S_name"].ToString();
Label7.Text = dr["SID"].ToString();
Label2.Text = dr["phone"].ToString();
Label3.Text = dr["E_mail"].ToString();
Label4.Text = dr["Department"].ToString();
Label6.Text = dr["Password"].ToString();
dr.Close();
}
con.Close();
List<Label> labels = new List<Label>();
for(int i =0; i <= 6; i++)
{
Label label = new Label();
labels.Add(label);
}
con.Open();
com.ExecuteNonQuery();
SqlDataAdapter sda = new SqlDataAdapter(com);
DataTable dt = new DataTable();
sda.Fill(dt);
com.ExecuteNonQuery();
con.Close();
}
private String button1WasClick = "false";
public static void SendEmail(String emailbody)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
using (MailMessage mailMessage = new MailMessage(ConfigurationManager.AppSettings["SMTPuser"],Label3.Text))
{
mailMessage.Subject = Label1.Text;
mailMessage.Body = "Hello amal you can log in the system This your ID:18819 username :amal";
using (SmtpClient smtp = new SmtpClient())
{
smtp.EnableSsl = true;
smtp.Host = ConfigurationManager.AppSettings["Host"];
smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnabelSSL"]);
NetworkCredential networkCred = new NetworkCredential(ConfigurationManager.AppSettings["SMTPuser"], ConfigurationManager.AppSettings["SMTPpassword"]);
smtp.UseDefaultCredentials = true;
smtp.Credentials = networkCred;
smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
smtp.Send(mailMessage);
ClientScript.RegisterStartupScript(GetType(), "alter", "alter(Email sent);", true);
}
}
}
private bool button2WasClick = false;
protected void Button2_Click(object sender, EventArgs e)
{
button2WasClick = true;
Response.Write("Email masseg is sent Succesfully");
using (MailMessage mailMessage = new MailMessage(ConfigurationManager.AppSettings["SMTPuser"], "monaxshroog@gamil.com"))
{
mailMessage.Subject = Label1.Text;
mailMessage.Body = "Hello amal your request to be a suporvisor for senior project is not agread by Coordenator for mor daital :<br/>";
using (SmtpClient smtp = new SmtpClient())
{
smtp.EnableSsl = true;
smtp.Host = ConfigurationManager.AppSettings["Host"];
smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnabelSSL"]);
NetworkCredential networkCred = new NetworkCredential(ConfigurationManager.AppSettings["SMTPuser"], ConfigurationManager.AppSettings["SMTPpassword"]);
smtp.UseDefaultCredentials = true;
smtp.Credentials = networkCred;
smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
smtp.Send(mailMessage);
ClientScript.RegisterStartupScript(GetType(), "alter", "alter(Email sent);", true);
}
}
}
}
}
What I have tried:
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.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Configuration;
namespace exam
{
public partial class RegistrationTransaction : System.Web.UI.Page
{
SqlConnection cnn = new SqlConnection();
protected void Page_Load(object sender, EventArgs e)
{
cnn.ConnectionString = ConfigurationManager.ConnectionStrings["seniorConnectionString"].ConnectionString;
if (cnn.State == ConnectionState.Closed)
{
cnn.Open();
}
SqlCommand cm = new SqlCommand("select S_name from dbo.[Suporvisor(commtiee)] ", cnn);
cm.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cm);
DataSet dt = new DataSet();
da.Fill(dt);
Repeater Repeater1 = new Repeater();
Repeater1.DataSource = dt;
Repeater1.DataBind();
if (cnn.State == ConnectionState.Open)
{
cnn.Close();
}
foreach (RepeaterItem repeatItem in Repeater1.Items)
{
if (repeatItem.ItemIndex == 0)
{
RepeaterItem headerItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Header);
HtmlGenericControl hTag = new HtmlGenericControl("h4");
hTag.InnerHtml = "Suporvisor Rigestration Transaction";
repeatItem.Controls.Add(hTag);
}
RepeaterItem repeaterItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Item);
LinkButton lnk = new LinkButton();
lnk.ID = "lnk_itemname";
lnk.Text = String.Format("{0}", (dt.Tables[0].Rows[repeatItem.ItemIndex]["S_name"]));
lnk.Click += new EventHandler(click);
HttpContext H = HttpContext.Current;
String name = H.Request[lnk.Text];
repeatItem.Controls.Add(lnk);
repeaterItem = new RepeaterItem(repeatItem.ItemIndex, ListItemType.Separator);
LiteralControl ltrlHR = new LiteralControl();
ltrlHR.Text = "<hr />";
repeatItem.Controls.Add(ltrlHR); SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["seniorConnectionString"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("select*from dbo.[Suporvisor(commtiee)]", con);
SqlDataReader dr;
dr = com.ExecuteReader();
if (dr.HasRows == true)
{
while (dr.Read())
if (lnk.Text.Equals("S_name"))
{
Server.Transfer("~/SuporvisorRegistTran.aspx");
}
Server.Transfer("~/SuporvisorRegistTran.aspx");
}
}
Panel1.Controls.Add(Repeater1);
PlaceHolder1.Controls.Add(Panel1);
}
protected void click (object sender , EventArgs e)
{
Response.Redirect("~/SuporvisorRegistTran.aspx");
}
}
}