Click here to Skip to main content
15,917,174 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI,

This my code:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd, cmd1;
    SqlDataAdapter da;
    SqlDataReader reader;
    string str;
    protected void Page_Load(object sender, EventArgs e)
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
        con.Open();
        cmd = new SqlCommand("select ID, Name, Gender, Relationship from Registration", con);
        reader = cmd.ExecuteReader();

        gvUsers.DataSource = reader;

        gvUsers.DataBind();
        reader.Dispose();
        reader.Close();

        //bindresult();


        con.Close();

    }
    protected void gvUsers_SelectedIndexChanged(object sender, EventArgs e)
    {
        str = gvUsers.SelectedDataKey.Value.ToString();
        gvUsers.SelectedRow.BackColor = System.Drawing.Color.SkyBlue;
        cmd1 = new SqlCommand("select * from Registration where ID = '" + str + "'", con);
        DataTable dt = new DataTable();
        da = new SqlDataAdapter(cmd1);
        da.Fill(dt);
        gvDetails.DataSource = dt;
        gvDetails.DataBind();

    }
}


In the first gridview, i am using a link button where a JavaScript function is called. This function would open a div with the second grid in it.

However, i am getting an empty div. Please help me what i wrong with my code.

I am new programmer so really appreciate any help!

Thanks
Posted

1 solution

hi,

The problem is that in gvUsers_SelectedIndexChanged() event you are using con which is just declared not initialized,make an object of con in this event like you did in Page_Load :)
 
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