EditTemplate Databind多个下拉列表

时间:2013-11-19 15:10:27

标签: c# asp.net

我正在加载Form的Edittemplate以更改db中的记录。表单正确地提取信息。当我在Edittemplate中对一个或多个Dropdownlist(State,Country,JobType)进行更改时,即使我没有更改原始值,一些值在保存时也会返回null。我做错了什么?

<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1" DefaultMode="Insert"
     OnItemCreated="FormView1_OnItemCreated" OnItemUpdated="FormView1_OnItemUpdated">
    <EditItemTemplate>            
        <table>               
            <tr>                    
                <td>
                    <telerik:RadDropDownList ID="State" runat="server" DataSourceID="dseState" DataTextField="State" AppendDataBoundItems="true" DataValueField="State" SelectedValue='<%# Bind("State") %>'></telerik:RadDropDownList>
                    <asp:SqlDataSource ID="dseState" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
                                       ProviderName="System.Data.SqlClient" SelectCommand="SELECT ID, State FROM lkpState ORDER BY ID"></asp:SqlDataSource>
                </td>
            </tr>
            <tr>
                <td style="text-align:right;">
                    <strong>Country<span style="font-size: 8pt; color: red">*</span>:</strong>
                </td>
                <td \>
                    <telerik:RadDropDownList ID="Country" runat="server" DataSourceID="dsCountry" AppendDataBoundItems="true" DataTextField="Country" DataValueField="Country" SelectedValue='<%# Bind("Country") %>'></telerik:RadDropDownList>
                                         <asp:SqlDataSource ID="dsCountry" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
                                             ProviderName="System.Data.SqlClient" SelectCommand="SELECT ID, Country FROM lkpCountry ORDER BY ord, Country"></asp:SqlDataSource>      
                </td>
            </tr>                
            <tr>
                <td>
                    <strong>Job Type<span style="font-size: 8pt; color: red">*</span>:</strong></td>
                <td>
                    <telerik:RadDropDownList ID="JobType" runat="server" SelectedValue='<%# Bind("Job_Type") %>'>
                        <Items>
                            <telerik:DropDownListItem Text="Full Time" Value="Full Time" />
                            <telerik:DropDownListItem Text="Part Time" Value="Part Time" />                                
                        </Items>                            
                    </telerik:RadDropDownList>
                </td>
            </tr>

        </table>
        <br />            
        <telerik:RadButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
            Text="Update Job!" Font-Bold="True" ForeColor="Green" BorderColor="Green"></telerik:RadButton>
        &nbsp;
        <telerik:RadButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
            Text="Cancel" OnClick="UpdateCancelButton_Click" ForeColor="Red" BorderColor="Red"></telerik:RadButton>
        &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="font-size: 8pt"><span style="color: #ff0000">
            *Required Information<span></span></span></span>&nbsp;
    </EditItemTemplate>
</asp:FormView>    
        </td>
    </tr>
</table>    
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
      UpdateCommand="UPDATE [Jobs] SET [Job_Type] = @Job_Type, [State] = @State, [Country] = @Country  WHERE [Job_ID] = @Job_ID">
     <UpdateParameters>            
        <asp:Parameter Name="Job_Type" Type="String" />           
        <asp:Parameter Name="State" Type="String" />
        <asp:Parameter Name="Country" Type="String" />
    </UpdateParameters>
</asp:SqlDataSource>

背后的代码

 namespace Jobs
{
public partial class Jobs_Add_job : Telligent.Evolution.Controls.CSThemePage
{

    protected void FormView1_OnItemCreated(object sender, EventArgs e)
    {
        if (FormView1.CurrentMode == FormViewMode.Insert)
        {
            TextBox txtUserId = FormView1.FindControl("UserIDTextBox") as TextBox;
            txtUserId.Text = User.Identity.Name;
        }
    }

    protected void FormView1_OnItemUpdated(object sender, EventArgs e)
    {
        Response.Redirect("econsole.aspx");            
    }

    protected void UpdateCancelButton_Click(object sender, EventArgs e)
    {
        Response.Redirect("econsole.aspx");
    }

    protected void InsertButton_Click(object sender, EventArgs e)
    {
        JobConfirmed.Visible = true;
    }        

}

0 个答案:

没有答案