0

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

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

<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();
        }
4

1 回答 1

0

发布您的代码,但在我看来,您必须在网格 onrowdatabound 事件的下拉列表中设置选定的值 - 但基于您的问题的模糊性,我并不完全确定。

于 2011-05-13T12:40:27.677 回答