【发布时间】:2011-12-20 18:42:06
【问题描述】:
我有一个组合框和一个值列表。 如果我添加一个值并保存它,它应该出现在组合框中。但它只在我刷新页面后出现。它没有正确绑定数据。
我已将 DataBind() 放入
if (!Page.IsPostBack)
{
DataBind() ;
}
但以上没有帮助。 如何检查所有内容是否正确绑定。
请帮忙。 谢谢
protected void Page_Load(object sender, EventArgs e)
{
DataBind();
if (!Page.IsPostBack)
{
}
}
protected void btn_save_click(object sender, EventArgs e)
{
SqlCommand command_update = new SqlCommand("Update", connection_save1);
command_update.CommandType = System.Data.CommandType.StoredProcedure;
command_update.Parameters.Add(new SqlParameter("@ViewId", Int32.Parse(Id.Value)));
SqlParameter Returns = new SqlParameter("@ReturnCode", SqlDbType.Char);
Returns.Size = 1;
Returns.Direction = ParameterDirection.Output;
command_insert.Parameters.Add(Returns);
bSuccess = command_insert.Parameters["@ReturnCode"].Value.ToString();
if (bSuccess == "1")
{
//Response.Write("Insert successful");
dd_group.DataBind();
dd_group.SelectedValue = command_insert.Parameters["@ReturnCode"].Value.ToString().Trim();
}
}
这里是html
<asp:DropDownList ID="dd_group" DataSourceID="sp" DataTextField="maintitle"
DataValueField="Id" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="group_SelectedIndexChanged1" Height="24px"
Width="50%">
</asp:DropDownList>
<asp:SqlDataSource ID="sp" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="GetIds" runat="server" SelectCommandType="StoredProcedure">
【问题讨论】:
标签: c# javascript asp.net sql