Jay1b Posted March 20, 2006 Posted March 20, 2006 Hi, i have what i consider a silly problem..... I'm trying to find the data that is in a certain cell in the datagrid. I was using the below Label20.Text = dgDepartments.Items(2).Cells(2).Text Now i SWEAR that was working, i've come back to it after playing around with something else and its not working... however i am SO sure it was... Firstly, could someone please tell me whether that would be the right code to retrieve the data and put it into the label. Currently this doesnt work, and i cant for the life of me figure out why, it doesnt cause an error, it just displays blank. And yes there is data in the table even after allowing for arrays starting at 0. Secondly, if this code is right, what could of stopped it from working? Thanks. Quote
Jay1b Posted March 20, 2006 Author Posted March 20, 2006 I've even put this line in above it dgDepartments.Items(2).Cells(2).ForeColor = Drawing.Color.Crimson Which successfully changes the colour of the writing on that cell, it just cant find the text.... :( Quote
Jay1b Posted March 21, 2006 Author Posted March 21, 2006 I've figured out this must be something to do with the fact i'm using now a template field of those cells. Quote
Jay1b Posted March 21, 2006 Author Posted March 21, 2006 (edited) Could someone please tell me how i can find the contents of a template field in a datagrid? The code is below <asp:DataGrid ID="dgDepartments" runat="server" AutoGenerateColumns="False" OnEditCommand="dgDepartmentHead_Edit" OnCancelCommand="dgDepartmentHead_Cancel" OnUpdateCommand="dgDepartmentHead_Update" OnDeleteCommand="dgDepartmentHead_Delete" ShowFooter="True" OnItemCommand="DoCommand"> <Columns> <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="OK" ButtonType="PushButton" /> <asp:TemplateColumn HeaderText="Department"> <ItemTemplate> <asp:Button CommandName="Delete" Text="Delete" ID="btnDel" runat="server" OnClientClick="javascript:return confirm('Are you sure you want to delete the department?')" /> </ItemTemplate> <FooterTemplate> <asp:Button CommandName="Insert" Text="Add" ID="btnAdd" runat="server" /> </FooterTemplate> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="Department"> <ItemTemplate> <%#DataBinder.Eval(Container.DataItem, "Department")%> </ItemTemplate> <FooterTemplate> <asp:TextBox ID="txtDepartmentNew" runat="server" /> </FooterTemplate> <ItemStyle Width="80%" /> </asp:TemplateColumn> <asp:TemplateColumn HeaderText="DepartmentHead"> <ItemTemplate> <%#DataBinder.Eval(Container.DataItem, "DepartmentHead")%> </ItemTemplate> <EditItemTemplate> <asp:DropDownList ID="ddDepartmentHead" runat="server" DataTextField="DepartmentHead" DataValueField="username" DataSource='<%# GetDepartmentHeads() %>' SelectedIndex='<%# GetSelIndex(Container.DataItem("DepartmentHead")) %>' /> </EditItemTemplate> <FooterTemplate> <asp:DropDownList ID="ddDepartmentHeadNew" runat="server" DataTextField="DepartmentHead" DataValueField="username" DataSource='<%# GetDepartmentHeads() %>' /> </FooterTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> Edited March 21, 2006 by PlausiblyDamp Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.