Showing posts with label dropdownlist. Show all posts
Showing posts with label dropdownlist. Show all posts

Sunday, February 19, 2012

Gridview question

Sqldatasources are used for a dropdownlist and a gridview. How can the dropdownlist selection refresh the gridview? This is done programmatically in ASP.NET 1.1 code behind. Can it be done in ASP.NET 2.0 without code behind? Thanks.

Hi,

the SqlDataSource controls hasfilterparameters that you can set through the wizard, or in markup, and then you can use for example the controlparameter:

<asp:ControlParameter Name="Title" ControlId="DropDownList1" PropertyName="SelectedValue"/>

Be sure totake a look at this example.

Grz, Kris.

|||

Thanks. But how can the following be implemented in the FilterParmeters?

Sub LoadGrid()
Dim sqlText As String
If IsPostBack And cboState.SelectedValue <> "0" Then
sqlText = "SELECT * FROM Customers WHERE State='" & cboState.SelectedValue & "'"
Else
sqlText = "SELECT * FROM Customers"
End If
gridCust.DataSource = GetDataView(sqlText, cnn)
gridCustDataBind()
End Sub

Gridview and DropDownList

Hello:

I have add a DropDownList to my GridView and binded the dropdownlist to a field from a select statement in the SQLDataSource. I have EnabledEditing for my GridView. The GridView is populated with information from the select statement. Some of the information returned from the select statement is null. The field where the dropdownlist is binded it is null in some cases and does not have a value that is in the dropdownlist so I get and error when I attempt to do an update.

'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Is there a way to get around this besides initializing all the columns in the table that are going to be binded to a dropdownlist to a value in the dropdownlist?

You can exclude the NULL from your SELECT statement by adding a where clause like: SELECT thefield FROm yourTable WHERE thefield IS NOT NULL. You don't need to worry about this NULL value for your test..