Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EditItemTemplate Dropdown

Status
Not open for further replies.

MaddogC

Programmer
Dec 4, 2003
134
0
0
GB
I have a gridview that has a templatecolumn for editing that contains a dropdownlist. The dropdown gets it's data from an objectdatasource and is working fine.

I now need to add a selectparamter to the objectdatasource which gets an id from the gridview. I need to do this as the dropdown contains different data for each row in the grid dependent on the ID.

How do I do this? I've tried adding a selectparamter which returns null. Can I get the selected value for a gridview in the onselecting handler?
 
Are you saying you have a dropdownlist, in a template column, and for each row the data can be different?
If so, you need to use the RowDataBound event of the grid to get access to the dropdownlist. Then grab the ID of the grid and pass to your objectdatasource.
If you were planning on using the same DS, I wouldn't, create a new ODS.

Jim
 
Here is my code for the columns in the gridview

<Columns>
<asp:BoundField DataField="FUNCID" HeaderText="id" SortExpression="FUNCID" Visible="true" >
<ItemStyle HorizontalAlign="Left" />
</asp:BoundField>
<asp:BoundField DataField="FUNCTION_NAME" HeaderText="Name" ReadOnly="True" SortExpression="NAME" >
<ItemStyle HorizontalAlign="Left" Width="60%" />
</asp:BoundField>



<asp:TemplateField HeaderText="Level" SortExpression="PERMISSION_LEVEL">
<ControlStyle />

<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("LEVEL_NAME") %>' Width="30%"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList CssClass="StandardText" Width="100px" DataSourceID="ObjectDataDDLLevel" DataTextField="LEVEL_NAME" DataValueField="PERMISSION_LEVEL"
ID="DropDownList2" runat="server" SelectedValue='<%# Bind("PERMISSION_LEVEL") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemStyle Wrap="False" HorizontalAlign="Left" Width="30%" />
</asp:TemplateField>

<asp:CommandField ShowEditButton="True"/>

</Columns>

When I click on the Edit Button I need to pass the value from the FUNCID field to my data access layer to retrieve the values for the dropdownlist dependent upon the FUNCID.

Does this clarify your understanding?, I think you are on the tight lines.
 
Code:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
   If e.Row.RowState = DataControlRowState.Edit Then
      Dim id As Integer
      id = Convert.ToInt16(e.Row.Cells(1).Text)
      ''Pass the ID your DAL ....
   End If
End Sub
 
Thanks for the post. However when I click on the edit button the e.Row.RowState is still showing as "Normal" rather than edit. Do you know why this should be?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top