Reputation: 53
I want to fill textboxes when a user clicks on a row. I don't want to use grdUser..SelectedRow.Cells[1].Text
because my datagrid has a summary of the user details e.g. name, SSNumber, email.
if I click on the row then I want all the user details should load into textboxes. How would I do that?
I would like to use a sql query but then my where
clause should use SSNumber
but not sure that's best practise.
C# or vb help welcome.
Upvotes: 0
Views: 693
Reputation: 309
First, get the index of the selected row then get the value of the specific cell
Dim dgv_active_Row as Integer= dgv.CurrentRow.Index
TextBox1.Text = dgv.Item(1, dgv_active_Row).Value
'1' is the index of the specific column where you want to get the value of the textbox
Upvotes: 0
Reputation: 2453
You can add Attributes to the Row created and when the user clicks that row redirect them to a page with the Id of the object you want to display. I know you are using a datagrid my example is using a GridView
For example on Row created
protected void ListGrid_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType .DataRow)
{
e.Row.Attributes[ "onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';" ;
e.Row.Attributes[ "onmouseout"] = "this.style.textDecoration='none';" ;
e.Row.ToolTip = "Click to select row";
e.Row.Attributes[ "onclick"] = "Javascript:window.location = '" + ResolveClientUrl("~/PickList/ScanPickListItem.aspx" ) + "?PLRID=" + DataBinder.Eval(e.Row.DataItem, "ScreenRowId" ) + "'";
}
}
Upvotes: 1