Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ive been struggling all morning over this issue...it it possible, i need the value to for a particular datarow

here is the code ive tried


C#
protected void Get_RowData(object sender, GridViewCommandEventArgs e)
    {

        //int ind = GridView1.SelectedIndex;
        //string id = GridView1.DataKeys[ind].Value.ToString();
 
        if (e.CommandName == "Modify")
        {
            GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
            int index = row.RowIndex;
            int employeeID = Convert.ToInt32(GridView1.DataKeys[index].Value);

            table1.Visible = true;
      // int index = Convert.ToInt32(e.CommandArgument);

          //  string indextest = GridView1.DataKeys[Convert.ToInt32(e.CommandArgument)].Values["airid"].ToString();

            SqlConnection con = new SqlConnection(connectionString);
            con.Open();
            //SqlDataAdapter da = new SqlDataAdapter("sp_GetAir", con);

            DataSet ds2 = _ds.Copy();
           // da.Fill(ds2);
            DataTable dt = ds2.Tables[0];
            DataRow dr = dt.Rows[employeeID];
            txtairline.Text = dr["airlines"].ToString();
            txtdepcity.Text = dr["depcity"].ToString();
            txtdeptime.Text = dr["deptime"].ToString();
            txtdepdate.Text = dr["depdate"].ToString();
            txtarrvcity.Text = dr["arrvcity"].ToString();
            txtarrvtime.Text = dr["arrvtime"].ToString();
            txtarrvdate.Text = dr["arrvdate"].ToString();
                      
        }

    }
Posted
Updated 30-Nov-11 23:41pm

1 solution

This is the line you have used in your code to get the datakey value in particular row.

int employeeID = Convert.ToInt32(GridView1.DataKeys[index].Value);
 
Share this answer
 
Comments
Dunstan89 1-Dec-11 6:00am    
yea i know that...but the thing for the first row i get an error saying

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

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