ASP下拉列表选择值

时间:2011-05-13 12:34:47

标签: asp.net gridview drop-down-menu selectedvalue

我有一个带有“日期”字段的页面作为下拉列表和提交按钮。当我点击提交时,所选值将显示在其他页面的网格视图中。

现在在网格视图中,我有一个像“编辑”这样的字段,当我点击它时,它会被导航到带有该日期值的第一页。问题是这次“从网格视图传递的日期”未在下拉列表中显示选定值。

<asp:TemplateField HeaderText="DOB" SortExpression="dob">
            <ItemTemplate>
                   <asp:Label ID="lbldob" runat="server" Text='<%# Bind("dob") %>'>
                   </asp:Label>
            </ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Edit">
            <ItemTemplate>
                     <asp:LinkButton ID="hypeno" CommandName="cmdBind" runat="server" Text='<%# Eval("id") %>' CommandArgument='<%# Bind("id") %>'>
                     </asp:LinkButton>
           </ItemTemplate>
</asp:TemplateField>

代码:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "cmdBind")
        {
            string id = e.CommandArgument.ToString();
            LinkButton lb = (LinkButton)e.CommandSource;

            Response.Redirect("/practice/registation.aspx?id=" + id +"&type=edit");
        }

    }

      string type = Request.QueryString["type"].ToString();
       if (type == "edit")
       {                 connection con = new connection();
                     DataSet ds;
                     ds = con.select("select dob from registration where id='"+Request.QueryString["id"].ToString()+"'");

      drddate.SelectedItem.Text= ds.Tables[0].Rows[0][0].ToString();
        }

1 个答案:

答案 0 :(得分:0)

发布你的代码,但听起来像是你必须在网格onrowdatabound事件的下拉列表中设置所选值 - 但我不能完全确定你问题的模糊性。