Click here to Skip to main content
15,902,938 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi i am using template field gridvew . i want get gridview field values for that i use,
gvProjectStatus.Rows[2].Cells[3].Text;

i have values in 2 X 3 cell but i am getting null only

please help me
Posted
Updated 14-Dec-10 22:05pm
v2
Comments
Hiren solanki 15-Dec-10 3:53am    
Give me error you are getting as a comment inside my answer.
Toniyo Jackson 15-Dec-10 4:05am    
Always write your code inside code block
T.Saravanann 15-Dec-10 4:17am    
Check the selected cell value is empty (or) have a value.In your code there is no error.

Try:
MIDL
gvProjectStatus.Rows[1].Cells[2].Text;

for 2 X 3 cell!
 
Share this answer
 
Comments
Hiren solanki 15-Dec-10 3:34am    
that's good catch sandeep, but I think he should have get error of index out of range If he uses that, But He hasn't mentioned it.

Any way take a 5 !
Sandeep Mewara 15-Dec-10 3:36am    
Well, OP didnt said that it was the last column/row! :)
Follow the suggestion provided by sandeep.

Further more if you have kept control's inside TemplateField then you will not be able to fetch the value directly.

Suppose there's a Lable inside TemplateField Then use following.

Label lbl = (Label)gridview.Rows[1].Cells[2].Controls[0];
if(lbl!= null)
String textInsideCell = lbl.text;
 
Share this answer
 
Comments
srinivasvempa 15-Dec-10 3:51am    
i have done like what u mention above but even i am not getting value have a look on below my code
con = objDL.createNewConnection();
string str = "select * from PM_SiteEstimation";
da = new SqlDataAdapter(str, con);
da.Fill(ds, "PM_SiteEstimation");
gvProjectStatus.DataSource = ds.Tables[0];
gvProjectStatus.DataBind();
for (int i = 0; i < gvProjectStatus.Rows.Count; i++)
{
Label lbl = (Label)gvProjectStatus.Rows[1].Cells[2].Controls[0];
string estim = lbl.Text;
}
T.Saravanann 15-Dec-10 4:19am    
Hi Srinivasvempa,

You get particular Cell value only then why are you using a loop concept.
TextBox textname=(TextBox)GridView1.Row.FindCOntrol["TextBoxname"]
 
Share this answer
 
Comments
Hiren solanki 16-Dec-10 5:56am    
You should see already given answers to avoid redundant answer.
U can Try
Label.text=gridview.Rows[1].Cells[2].Value.toString();

Or u can use
Label.text= gridview.CurrentRows.Cell[2].value.tostring();

if you are getting value after clicking on cell..

Just suggestion.
consider it if you think i got ur question..
 
Share this answer
 
v2
Comments
Toniyo Jackson 15-Dec-10 4:06am    
Always write your code inside code block
Hiren solanki 15-Dec-10 4:21am    
Have you tried that it works ever ?

I think .Value Property is not supported there.
srinivasvempa 15-Dec-10 5:15am    
ya value properity not working
send me more

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900