Hi friends i have one small doubt..Actually myclient requirement is whenever i click the gridview row that particular row will select and store that particular row values in one string variable.Any one know the answer please send the reply.
How to get the particularRow values in onclick situation in gridview
Collapse
X
-
Tags: None
-
Just use the SelectedIndex property to get to the right row, and then traverse the cells of that row, appending each onto a string. -
Thanks for ur reply.Actually i need how can select the row in the grid.if i select the particular row which event i can raise?please helpme.Comment
-
Make sure that you enable selection for your gridview. The event is called SelectedIndexCh anged.Comment
-
Originally posted by insertAliasMake sure that you enable selection for your gridview. The event is called SelectedIndexCh anged.
String str = "";
String intRow = "";
Point row = [DataGridView].CurrentCellAdd ress;
intRow = Convert.ToStrin g(row);
if (intRow.Length == 9)
{
str = intRow.Substrin g(7, 1);
}
else
{
str = intRow.Substrin g(7, 2);
}
int n = int.Parse(str);
Use "n" as the row index.
Although this works.
It is better to use the SelectedIndex property.Comment
-
Originally posted by deathprincessI have a problem like that before and created this code to identify the selected row in dataridview:
String str = "";
String intRow = "";
Point row = [DataGridView].CurrentCellAdd ress;
intRow = Convert.ToStrin g(row);
if (intRow.Length == 9)
{
str = intRow.Substrin g(7, 1);
}
else
{
str = intRow.Substrin g(7, 2);
}
int n = int.Parse(str);
Use "n" as the row index.
Although this works.
It is better to use the SelectedIndex property.Comment
-
Thanks for your reply.Sorry for my latereply.Actua lly i need how can select the GridRow.Means if i click on row i need the total details of that row.But whenever i select the row this time i will get the cell details.But need Row and Cell details also.Waiting for ur reply.Comment
-
add OnRowCommand="g rd_RowCommand" to gridview
add a column
<asp:ButtonFiel d ButtonType="But ton" CommandName="cm d" Text="CMD" />
protected void grdApplicationS ettings_RowComm and(object sender, GridViewCommand EventArgs e)
{
GridView customersGridVi ew = (GridView)e.Com mandSource;
int index = Convert.ToInt32 (e.CommandArgum ent);
GridViewRow row = customersGridVi ew.Rows[index];
if (e.CommandName. Equals("CMD", StringCompariso n.InvariantCult ureIgnoreCase))
{ //do something
}
}Comment
-
Originally posted by phanimadhavThanks for your reply.Sorry for my latereply.Actua lly i need how can select the GridRow.Means if i click on row i need the total details of that row.But whenever i select the row this time i will get the cell details.But need Row and Cell details also.Waiting for ur reply.
then use the datagridview.Se lectedRows[0].Cells[cell index].value
This gets the value associated with the cell of the selected row.Comment
Comment