Why does this work

E

Evan M.

I have the following page:

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
protected int GetTestVal (object obj) {
if (obj == DBNull.Value)
return 2;
else
return (bool) obj ? 1 : 0;
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:RadioButtonList ID="TestValueRadioButtonList" runat="server"
DataSourceID="TestValuesDataSource" DataTextField="NullTestID"
DataValueField="NullTestID" AutoPostBack="true" RepeatColumns="3">
</asp:RadioButtonList>
</div>
<div style="margin-top: 2em;">
<asp:FormView ID="FormView1" runat="server"
DataKeyNames="NullTestID" DataSourceID="SelectedTestValue"
DefaultMode="Edit">
<EditItemTemplate>
NullTestID:
<asp:Label ID="NullTestIDLabel1" runat="server" Text='<%#
Eval("NullTestID") %>' /><br />
NullBit:
<asp:RadioButtonList ID="RadioButtonList1" runat="server"
SelectedValue='<%# GetTestVal(Eval("NullBit")) %>'>
<asp:ListItem Text="True" Value="1" />
<asp:ListItem Text="False" Value="0" />
<asp:ListItem Text="Unknown" Value="2" />
</asp:RadioButtonList><br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update"
Text="Update">
</asp:LinkButton>
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel"
Text="Cancel">
</asp:LinkButton>
</EditItemTemplate>
</asp:FormView>

</div>
</form>
<asp:SqlDataSource ID="TestValuesDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:TempEmployeesConnectionString
%>"
SelectCommand="SELECT [NullTestID] FROM [NullTest]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SelectedTestValue" runat="server"
ConnectionString="<%$ ConnectionStrings:TempEmployeesConnectionString
%>"
SelectCommand="SELECT [NullTestID], [NullBit] FROM [NullTest] WHERE
([NullTestID] = @NullTestID)"
UpdateCommand="UPDATE NullTest SET NullBit = @NullBit WHERE
NullTestID = @NullTestID">
<SelectParameters>
<asp:ControlParameter ControlID="TestValueRadioButtonList"
DefaultValue="1"
Name="NullTestID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:parameter Name="NullBit" />
<asp:parameter Name="NullTestID" />
</UpdateParameters>
</asp:SqlDataSource>
</body>
</html>

Undelaying database table has two columns: NullTestID(int) and
NullBit(bit, allow null).

I get how the function works properly to map the database NULL value
so that it selects the "Unknown" option in the radio button list, but
why is it that it works going the other way around, where the update
will insert null back into the database when Unknown is selected?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top