Click here to Skip to main content
Sign Up to vote bad
good
in gridview i have listed many names from database
while selecting a row i need the names to be displayed in label how to do?...
 

please help me
 
i tried
GridViewRow row = CustomersGridView.SelectedRow;
 
MessageLabel.Text = "You selected " + row.Cells[2].Text + ".";
 
its not working while using break point
in .Text is blank
Posted 13 Dec '12 - 18:56

Comments
Kiran Susarla - 14 Dec '12 - 1:02
Are the columns databound to some database fields? how did you populate the grid? Can you please show your code here?
sreeCoderMan - 14 Dec '12 - 1:07
yeah databound to my database i used <%# DataBinder.Eval (Container.DataItem, "Name") %>
Krunal Rohit - 14 Dec '12 - 1:38
If I'm not mistaken, then GridViewRow row = CustomersGridView.SelectedRow; MessageLabel.Text = "You selected " + row.Cells[2].Text + "."; is from MSDN...
sreeCoderMan - 14 Dec '12 - 1:48
i tried this but its not working in my databound gridview

2 solutions

First you need to wrap your code in a Label or Literal control so that you can reference it properly. What's happening is that there's no way for the system to keep track of it, because there's no control associated with the text. It's the control's responsibility to add its contents to viewstate.
 
You need to use gridView.FindControl("controlName"); to get the control in the row. From there you can get at its properties including Text.
 
You can also get at the DataItem property of the Row in question and cast it to the appropriate type and extract the information directly.
 
Courtesy http://stackoverflow.com/questions/121722/getting-value-from-a-cell-from-a-gridview-on-rowdatabound-event[^]
  Permalink  
Comments
sreeCoderMan - 14 Dec '12 - 1:35
i couldnt able to figured it out can u please show me an example or demo
http://www.vkinfotek.com/gridview/gridview-selectedindexchanged-event.html[^]
 
protected void GridView1_DataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[0].Text.Contains("bla bla bla"))
            {
                e.Row.Cells[0].Forecolor = System.Drawing.Color.Aqua;
            }
        }
    }
  Permalink  
Comments
sreeCoderMan - 14 Dec '12 - 1:44
it works for simple gridview... but here its databound ... can u please show me a demo code or demo example
Krunal Rohit - 14 Dec '12 - 1:48
Solution been updated...
sreeCoderMan - 14 Dec '12 - 1:54
let me try this

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 325
1 Mohammed Hameed 123
2 Sergey Alexandrovich Kryukov 115
3 Santhosh G_ 103
4 Ron Beyer 89
0 Sergey Alexandrovich Kryukov 8,286
1 OriginalGriff 6,561
2 CPallini 3,533
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 14 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid