|
| |
User Groups : Forums : SiteExperts :
Microsoft .NET
:  | How to access a certain datagrid cell programatically without using index Hi! This is my first post here, so be gentle.
I am trying to access a certain cell on a row in a DataGrid. I am able to access its contens using an index value for the desired column, like this:
foreach(DataGridItem gridItem in DataGrid1.Items) { gridItem.Cells[4].BackColor=Color.LightBlue; }
Where the '4' is the index of the following column:
< asp:BoundColumn DataField="lName" HeaderText="Last name">< /asp:BoundColumn>
This will work fine as long as the indexes don't change, but in case someone adds a column in the middle of the grid, this will no longer return the desired result.
Does anyone have any idea how to access the 4th cell by it's name or dataField or anything more dynamic than the index?
Thank you in advance.Started By TomppiF on Nov 8, 2005 at 12:33:55 PM This message has been edited. |  | | 2 Response(s) | Reply |
| Earlier Replies | Replies 1 to 2 of 2 | Later Replies |  | TomppiF on Nov 9, 2005 at 8:09:42 AM (# 1) This message has been edited.I found a solution myself I exchanged all the BoundColumns for TemplateColumns and added Labels to these. I then set the DataSource for them through the Text property, like this:
< asp:TemplateColumn HeaderText="Gender"> < ItemTemplate>
< asp:Label ID="lblGender" Runat="server" Text='< %#Convert.ToString(DataBinder.Eval(Container.DataItem,"Gender"))% >'> < /asp:Label>
< /ItemTemplate> < /asp:TemplateColumn>
This made it possible to programatically access the contents of a cell with the FindControl() method.
foreach(DataGridItem gridItem in DataGrid1.Items) { Label lblTemp = (Label)gridItem.FindControl("lblGender"); string Gender = lblTemp.Text; lblTemp.BackColor=Color.LightBlue; }
At least like this I don't have to use indexes. But if anyone has a different solution, with which it isn't necessary to create templatecolumns and labels, please don't hesitate to post it here.
Thank you. hopeless_soul on Nov 20, 2005 at 2:59:50 PM (# 2)I have been trying to get my Dell Latitude LT to accept my linksys WPC11 instant wireless internet card. The computer is windows '95. I have tried to reload the driver from the linksys website and have also used different cards to try to make it work. The card has the "link active" light on. No icons will apear in the bottom right corner for connection statis. Also, the computer doesnt have any cd rom or floppy drive. I have been using my iomega "click" pc card drive to bring files between my comps to make things work. Please help me with this! If You have any ideas about how to do this Please either post it here, but i would rather You send comments to:
jordan_selby@hotmail.com
Thanks and PLEASE HELP!!!
| | Earlier Replies | Replies 1 to 2 of 2 | Later Replies |
To respond to a discussion, you must first logon.
If you are not registered, please register yourself to become a member of the SiteExperts.community.
|