Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Using a databound dropdown within datagrid

Author  Topic 

ninel
Posting Yak Master

141 Posts

Posted - 2007-01-26 : 16:48:10
I have a dropdownlist box within a datagrid that is populated with values that come from a database.

What I need is....
When a user selects a different value in the dropdown , on the autopostback I need to update the database with that value and then re-display the datagrid with the dropdown having the new value from the database.

Here's my code so far:

HTML:
<asp:datagrid id="grdResults" runat="server" Height="50px" Width="1200px" Font-Names="Tahoma"
Font-Size="XX-Small" ForeColor="Black" HorizontalAlign="Center" CellSpacing="1" BorderStyle="Solid" AutoGenerateColumns="False"
CellPadding="1" PageSize="1" BorderColor="Silver">
<AlternatingItemStyle CssClass="GridAltItem"></AlternatingItemStyle>
<HeaderStyle Font-Size="XX-small" Font-Bold="True"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="iID" visible="False" HeaderText="ID"></asp:BoundColumn>
<asp:BoundColumn DataField="iExceptionId" visible="False" HeaderText="ExceptionId"></asp:BoundColumn>
<asp:BoundColumn DataField="sType" HeaderText="Type"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Status">
<ItemTemplate>
<asp:DropDownList AutoPostback="true" id="ddlStatus" DataSource="<%#BindState()%>" TextField="sStatusName" DataValueField="iCmOtdExceptionStatusId" runat="server" Font-Name="Tahoma" Font-Size ="xx-small" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

VB.NET:
This populates the dropdown within the datagrid.
Public Function BindState()
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("connString"))
Dim myCommand As SqlCommand = New SqlCommand("uspGetOTDExceptionStatus", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
myConnection.Open()
Return myCommand.ExecuteReader(CommandBehavior.CloseConnection)
End Function


I can't figure out in which event I need to capture the new dropdown value and then call the stored proc that updates the value in the database.

Can someone help me please?

Thanks,
Ninel



snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2007-01-26 : 17:20:17
You'll need to use one of the datagrid events, probably the UpdateCommand - there's a very good article that you should take a look at to help you with all of the ins and outs of using controls in grid columns here
http://msdn2.microsoft.com/en-us/library/aa479316.aspx
Go to Top of Page
   

- Advertisement -