Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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.... :(

Posted (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 by PlausiblyDamp

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...