datagrid edit textbox

using asp.net (vb), i have a datagrid that allows editing.

i'm wondering why when i click on the edit button, all fields change to textboxes and not just the ones i've made an EditItemTemplate column for.

any suggestions how i'd prevent all of them becoming editable?

'-----------------------------------------------------------------

sub dgProject_Edit(sender As Object, e As DataGridCommandEventArgs)
      
      dgProject.EditItemIndex = CInt(E.Item.ItemIndex)
      
      Call DisplayProjectDatagrid(Nothing, Nothing)
      
end sub

'-----------------------------------------------------------------

<asp:DataGrid
                  id=dgProject  
                  OnItemDataBound="dgProject_ItemDataBound"
                  OnUpdateCommand="dgProject_Update"
                  OnCancelCommand="dgProject_Cancel"
                  OnEditCommand="dgProject_Edit"
                  OnDeleteCommand="dgProject_Delete"
                  DataKeyField="fldProjectID"
                  HeaderStyle-BackColor="#000000"
                  HeaderStyle-Font-Bold="True"
                  HeaderStyle-ForeColor="#ffffff"
                  runat="server"
                  BorderWidth="0"
                  ShowFooter="True"
                  Width="100%"
                  AutoGenerateColumns="False">
            
            <Columns>

                  <asp:BoundColumn DataField="fldProjectID" Visible="False"/>
                  
                  
                  <asp:TemplateColumn HeaderText="Project Thumbnail" HeaderStyle-Width="150">
                  <ItemTemplate>
                  <asp:ImageButton CausesValidation=False
                        id="ibProjectThumbnail"
                        CommandName="DisplayPortfolio"
                        ImageUrl='<%# Container.DataItem("fldProjectThumbnail")%>'
                        runat="server"/>
                  </ItemTemplate>
                  </asp:TemplateColumn>
                  
                  
                  <asp:BoundColumn DataField="fldProjectName"  HeaderStyle-Width="180" HeaderText="Project Name" Visible="true"/>
                  
                  <asp:TemplateColumn HeaderText="Project Description" HeaderStyle-Width="300">
                        <ItemTemplate>
                              <asp:Label ID="lblOriginalProjectDescription" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "fldProjectDescription") %>' />
                        </ItemTemplate>
                        
                        <EditItemTemplate>
                              <asp:TextBox id="txtNewProjectDescription" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "fldProjectDescription") %>'/>
                        </EditItemTemplate>
                  </asp:TemplateColumn>
                  
                  
                  
                  <asp:ButtonColumn Text="Delete" HeaderStyle-Width="50" CommandName="Delete" />
                              
                  <asp:editcommandcolumn Edittext="Edit" canceltext="Cancel" updatetext="Update" HeaderStyle-Width="100" />
                  
            </Columns>

            <AlternatingItemStyle BackColor=#d8e4f8 />

            </asp:DataGrid>



thanks all.
LVL 1
vbnewbie01Asked:
Who is Participating?
 
TimCotteeConnect With a Mentor Head of Software ServicesCommented:
Hi vbnewbie01,

               <asp:BoundColumn DataField="fldProjectName"  HeaderStyle-Width="180" HeaderText="Project Name" Visible="true" ReadOnly="true"/>

Add the ReadOnly attribute to the column definition.

This will stop it.

Tim Cottee
0
 
TimCotteeHead of Software ServicesCommented:
vbnewbie01,

Of course there is also a checkbox to set this at design time if you are using the datagrid property builder to create your columns.

Tim
0
 
vbnewbie01Author Commented:
i always wondered what that property was for :)

thanks tim.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.