I am now here displaying a table of vacancies for a Job Seeker and along with that i am displaying a column named actions with two buttons "Apply job"
and "Save Job".
as now i handled the pressed events for the button but now i want to fetch the record of a particular row when the button of that particular row is pressed
and insert into the table as when we pressed apply job then data should be fetched and stored in the apply table.
Please help me.................
Thankyou
Vishal GilbilePosted Mar 25, 2013, 6:58 AM
The following line of code may solves your problem. where ever you are handling the Button Click event inside it write the following line of code.
GridViewRow row = ((Button)(GridViewRow)).NamingContainer;
From the above line of code you would get the row of the GridView whose button was clicked and from the row you will have to iterate through all the cells and store the values where you want to store. For instance I want to store the values inside a string variable by concatenating it with "|"
NOTE The below code will work only if your are using BoundFields inside the Gridview.
string str="";
for(int i=0;i
str+=row.cells[i].Text+"|";
}
If your are using TemplateFields then you will have to read the Control values inside the Template Fields.For Instance
/*
Over here you will have to store the Control Id for instance if i want to read the controls which are there inside ItemTemplate and I've only three field all having label control inside Item Template. Then i'll copy the id of all the label controls inside ItemTemplate and store it in an array
*/
string []controlsId={"lbl1","lbl2","lbl3"};
string str="";
for(int i=0;i
Label lbl=(Label)row.cells[i].FindControl(controlsID[i]);
str+=lbl.Text+"|";
}
Hope that Solves your problem.
With Regards,
Vishal Gilbile.