Hi all. I am new to asp and would like your help on a problem I am having.

I have a gridview and a button. The onclickevent of the button must place a certain value from the gridview into an int variable. The value I am trying to get from the gridview is the primarykey of the table bound to the gridview.

Here is some of my code:

string sComment = txtAddComment.Text.Trim();
              int iGigId = Convert.ToInt32(GridView1.SelectedDataKey.Value);
              

              string sConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
              SqlConnection Connection = new SqlConnection(sConnectionString);
              Connection.Open();

              string sSQL = "INSERT INTO tblComments VALUES ( @uGigID , @uComment)";

              SqlCommand Command1 = new SqlCommand(sSQL, Connection);
              Command1.Parameters.AddWithValue("@uGigID", iGigId);
              Command1.Parameters.AddWithValue("@uComment" , sComment);

              Command1.ExecuteNonQuery();

              Connection.Close();

The problem here is that iGigId always gets a "null" value...why?
Please help

Search for Naming Container..

Sorry this might seem brainless, but what do tou mean by "search for naming container"?

in google... :)

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.