I hope this is what you are looking for:
The SQL Data Source populating the "ddlInsuranceType_ET" is called
"sdsInsuranceType"
It contains the following look up records:
- InsTypeID, InsuranceType (FIELD NAMES)
- 1, "Medicare"
- 2, "MedicAID"
Therefore, the ddl shows Medicare and MedicAID
Now my customer record contins:
- CustID, CustName, II_InsuranceType (FIELD NAMES)
- 1, "Luis", "IBC"
- 2, "Alexey", "MedicAID"
Now, when look the record for Customer "Alexey", the "Selected Value"
of the ddl show "MedicAID". HOWEVER, when I look at the Customer
"Luis" record, the page craps out because "IBC" is not a valid item in
the ddl.
<asp
ropDownList AppendDataBoundItems="true" SelectedValue='<
%#Bind("II_InsuranceType") %>' ID="ddlInsuranceType_ET"
runat="server"
DataSourceID="sdsInsuranceType" DataTextField="InsuranceType"
DataValueField="InsuranceType" ToolTip="Select Insurance Type.">
<asp:ListItem Value=""></asp:ListItem>
</asp
ropDownList>
Hope that helps,
On Mar 16, 11:58 am, "Anon User" <
[email protected]>
wrote:
Okay, I got it! The only question is what do you want to do with that
InsuranceType, which does not exist. The
ddlInsuranceType_ET contains a key (which we don't have) and its
value.
1) SQL way.
Use a stored procedure to get the data.
I suppose, the sdsInsuranceType has something like this:
"SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType"
If you have a stored procedure (or maybe you have one already), you
can return @InsuranceType if it doesn't exist.
Here's the code you can use
CREATE PROCEDURE [dbo].[GetInsuranceType]
(
@InsuranceType varchar(100)
)
AS
BEGIN
IF EXISTS(SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType)
SELECT InsTypeID, InsuranceType FROM ... WHERE
InsuranceType=@InsuranceType
ELSE
SELECT -1, @InsuranceType
END
GO
You can call this procedure from your code as
"GetInsuranceType @InsuranceType"
In case of Luis/IBC it returns -1, IBC.
Here you have to think regarding the "-1" as I don't know what you
wanted to do with that key - it doesn't exist in the
database table.
2) Code-behind way.
string lookFor = "IBC";
DataSet ds = ... get a data set ... WHERE InsuranceType='" + lookFor
+"'";
if (ds.Tables[0].Rows.Count > 0)
{
ddlInsuranceType_ET.DataSource = ds;
ddlInsuranceType_ET.DataBind();} else { // for Luis/IBC
ddlInsuranceType_ET.Items.Clear();
ddlInsuranceType_ET.Items.Add(new ListItem(lookFor, "-1"));
}
or something like this- Hide quoted text -
- Show quoted text -