0

On a web form we have a DetailsView bound to a dataSource.

The property called "AutGenerateRows" is also set to true.

When the web form is displayed in a web browser, the data from the fields are shown.

We want to change the properties of some of the fields. When we display the "Fields" window, I noticed that the "Selected fields" ListBox only contained a CommandField and no other fields.

Can you tell me how to set up the DetailsView so we can change the properties of the fields?

The attached screen shots will show what is happening. There are many fields and we want to avoid typing in all the code needed to make the fields as template fields if possible.

These screen shots show what is happening:

Screen Shot 2012-09-02 at 7.07.59 AM

Screen Shot 2012-09-02 at 7.01.21 AM

Update: Thanks for your replies. With your help, we are now on the correct path. Here is what the finished web form looks like:

Screen Shot 2012-09-02 at 9.01.48 AM

Community
  • 1
  • 1
Emad-ud-deen
  • 4,734
  • 21
  • 87
  • 152
  • what do you want to do ? – Waqar Janjua Sep 02 '12 at 11:33
  • One of the fields is DepartmentID and we would like to make just that field as a TemplateField so we can change it into a DropDownList instead of the default TextBox. The purpose is to just let the user see the DepartmentName instead of the ID. If we can get it to be shown in "Selected fields" then I can click on "Conver this field into a TemplateField". – Emad-ud-deen Sep 02 '12 at 11:48

1 Answers1

1

For deparatment ID add a template field column From the fields window, add a templateField Column. Then go to aspx source code place a dropdownlist. Something like this:

<asp:TemplateField >
    <ItemTemplate>
        <asp:DropDownList ID="DDL" runat="server" DataTextField='<%# Eval("FieldName") %>' />
    </ItemTemplate>   
</asp:TemplateField>
Waqar Janjua
  • 6,113
  • 2
  • 26
  • 36
  • Thanks for the steps required to get the field to show. We do have a new issue. I will post the screen shot. The web form is now showing 2 Department ID fields. The first one is the ID which we want to hide and the other is the DepartmentNames DropDownList. Is there a way to hide the DepartmentID number field? – Emad-ud-deen Sep 02 '12 at 12:24
  • Thanks everyone for all your help in getting us going in the correct direction. I was able to get what I wanted now. If you look at the screen shot of the "Fields" window there is no plus(+) sign next to "BoundField" in "Available fields". That was throwing us completely off. I decided to click the "Refresh Schema" link and to my surprise a plus sign appeared next to "BoundField". After I opened the node, I double clicked on all the needed fields then un-ticked "Auto-generate fields" and that made the extra field disappear. Now we can set all the properties we need. – Emad-ud-deen Sep 02 '12 at 12:58
  • 1
    @Emad-ud-deen It is showing twice because you have set AutGenerateRows = "true". Delete the bound field column which contains Department ID then it will show only one column of Department ID which you added using Template Field. – Waqar Janjua Sep 02 '12 at 13:54