Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i wanted to load image from sql to asp.net page and its working when page is loaded but i want it to load when button1_click is done or when i select from dropdown list menu below is the code for button1_click and its not working please help me with this error thanks in advance for all my friends

C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindFiles();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
       /* if (!IsPostBack)
        {
            BindFiles();
        }*/
    }

    /// <summary>
    /// Binds the files.
    /// </summary>
    private void BindFiles()
    {
        DataTable table = new DataTable();

        SqlConnection _conn1 = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Northwind;Data Source=KACHU-PC\\SQLEXPRESS");
        {
            string sql = "SELECT imageid, bid, pid FROM myimages Order By bid";
            using (SqlCommand cmd = new SqlCommand(sql, _conn1))
            {
                using (SqlDataAdapter ad = new SqlDataAdapter(cmd))
                {
                    ad.Fill(table);
                }
            }
        }
        GridView1.DataSource = table;
        GridView1.DataBind();
    }
Posted
Updated 8-Apr-12 0:29am
v2
Comments
pietvredeveld 8-Apr-12 6:21am    
Please make you're code sample more readable by removing all commented coded. Make sure the comment in code sample is correct and in de correct place. Remember good code, does not need any comment!
Piet
[no name] 8-Apr-12 6:31am    
"It's not working" is not a good description of your problem. What is not working? What is the error that you are getting?

You do realize that you have the code inside your button click event handler is commented out don't you?
tanweer 8-Apr-12 6:38am    
hi, I am surprized why you put the check for not post back on the button click? remove it and test like:
protected void Button1_Click(object sender, EventArgs e)
{
BindFiles();
}
Mohamed Mitwalli 8-Apr-12 7:07am    
Agree with you
karthikh87 8-Apr-12 23:26pm    
in that code i just wanted to show exactly where i am placing code n thanks for reply n its working fine now

1 solution

in sqldataadapter you print ad.fill(table)
this is wrong
da.fill(table)is correct
 
Share this answer
 
Comments
vino2012 16-Apr-12 9:23am    
his adapter declaration is

using (SqlDataAdapter ad = new SqlDataAdapter(cmd))

then why you telling to use
'da.fill(table) is correct' ???????

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