I have created link button dynamically and attach event to this. but when I invoke this event from page_load or page_init this works. but when i invoke this event from any simple button this is not working. could anybody help me. My code is following :-
protected void test2()
{
Data Set d = new DataSet();
LinkButton[] links = new LinkButton[5];
d = test(); // function to create database and returning to it.
int r = d.Tables["House_hold"].Rows.Count;
for (int i = 0; i < r; i++)
{
links[i].Text = d.Tables["House_hold"].Rows[i][6].ToString() + "<br /><br />";
links[i].Click += new System.EventHandler(Lnkbut_Click);
Panel1.Controls.Add(links[i]);
}
____________________________________________________________________________
protected DataSet fetchdata(string a)
{
DataSet ds = new DataSet();
if (con.State == ConnectionState.Open)
con.Close();
string ConnectionString = "Data Source=COMPUTER6\\SQLEXPRESS;Initial Catalog=test_SRS;Integrated Security=True";
con.ConnectionString = ConnectionString;
con.Open();
String s = "SELECT * FROM HH_Member where HH_ID='" + a.Substring(0,2) + "'";
SqlDataAdapter da = new SqlDataAdapter(s, con);
da.Fill(ds, "HH_Member");
return ds;
}
_______________________________________________________
void Lnkbut_Click(object sender, EventArgs e)
{
DataSet d2 = new DataSet();
Label1.Text = "hello";
Response.Write(e.ToString());
Response.Write("hello");
LinkButton b = (LinkButton)sender;
string s = b.ID;
Label1.Text = s;
d2=fetchdata(b.Text);
GridView1.DataSource = d2.Tables["HH_Member"].DefaultView;
GridView1.DataBind();
}
archana.khare.395 0 Newbie Poster
vsmash 14 Dinosaur
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.