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();
}
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();
}