read row (1 field) from ItemIndex

  • Thread starter brian yeo via .NET 247
  • Start date
B

brian yeo via .NET 247

I could not fetch "userID/column0" since my datagrid does not usethe DataKeyField (due to reformatting of dates - not shown). TheItemIndex can be located from clicking Edit button. How do Iread the UserID (primary key) after locating the ItemIndex? If Icould get the UserID, this data will be passed into keyValue.

Please show sample as I am new to this stuff. Help isappreciated.

** DataGrid: **
column0 column1
Edit Delete John John English

** end

void DataGrid_Edit(object sender, DataGridCommandEventArgs e) {
if (!isEditing) {
DataGrid1.EditItemIndex = e.Item.ItemIndex;
Response.BufferOutput = true;

int keyValue = e.Item.ItemIndex; //eg 3
string strline ="http://localhost/Quote/Employee/AddUser.aspx?id="+keyValue;

Response.Redirect(strline,true);
}
}

void BindGrid() {
SqlConnection dbConnection = newSqlConnection(ConnectionString);
SqlCommand dbCommand = new SqlCommand();

dbCommand.CommandText = SelectCommand;
dbCommand.Connection = dbConnection;

SqlDataReader dr;
dbConnection.Open();
dr = dbCommand.ExecuteReader();

DataTable dt = new DataTable();
dt.Columns.Add("User ID");
dt.Columns.Add("Username");

while (dr.Read())
{
DataRow r;

r = dt.NewRow();
r[0] = dr["Uid"].ToString().Trim();
r[1] = dr["Username"].ToString().Trim();
dt.Rows.Add(r);
}

DataGrid1.DataSource = dt;
DataGrid1.DataBind();

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top