我想在下拉列表中使用DDL中的其他值向用户显示所选值。 [英] I want to display selected value to the user in Drop Downlist with the other values in DDL.

查看:78
本文介绍了我想在下拉列表中使用DDL中的其他值向用户显示所选值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.用户将填写表格,以相同的形式有一个下拉列表,只有两个值,即活动&无效。

2.填写表格后,用户将查看他的个人资料[所有个人资料将在Gridview中查看,现在基于Id

用户将点击编辑/查看Gridview中的按钮]。

3.On点击按钮,所有用户的记录都将在文本框和文本框中显示。如果他愿意,可以修改下拉菜单。

4.现在用户在查看他的个人资料时提交表格时,在DDL中选择了有效值

来改变DDl中的活动值为非活动(此处出现问题,在查看其配置文件时,只有1个值是显示在DDL中的
,即提交的值,如果用户想要选择其他值,则DDL然后他不能这样做


例如我选择孟买价值并在查看我的个人资料时提交表格我想将其更改为Thane

我不能只做一个值,即孟买在DDL中可见,而不是显示孟买& Thane both。



代码

1.User will fill the form, in the same form there is a drop down with only two values ie.Active & Inactive.
2.After filling the form user will view his profile[all the profiles will be viewed in Gridview,now based on Id
user will click the EDIT/VIEW button in Gridview].
3.On Clicking the button all the one user's record will be visible to him in textbox & Dropdown which can be modified if he wish to.
4.Now the user has selected Active value in DDL when submitted the form now on viewing his profile user wants
to change the Active value to Inactive in DDl(Here the problem comes,on viewing his profile only 1 value is
displayed in DDL ie the submitted value, if the user wants to select the other value in DDL then he cant do it
)
Eg I have selected Mumbai value and submitted the form now on viewing my profile I want to change it to Thane
which I cant do it as only 1 value i.e Mumbai is visible in DDL instead of displaying Mumbai & Thane both.

Codes

CREATE TABLE [dbo].[tblDat](
    [PKID] [int] IDENTITY(1,1) NOT NULL,
    [Query] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [IsActive] [bit] NULL
) ON [PRIMARY]

CREATE procedure usp_BindData
As
Begin
select PKID,Query,case IsActive when 1 then 'Active' else 'Deactive' end as [Status] from tblDat
End

CREATE procedure usp_GetData
(
@PKID int 
)
As
Begin
select PKID,Query,case IsActive when 1 then 'Active' else 'Deactive' end as [Status] from tblDat where PKID=@PKID
End




<asp:TextBox ID ="txtQuery" runat="server"></asp:TextBox>
    <asp:DropDownList ID="ddlStatus" runat="server">
    <asp:ListItem Text="--Select--"></asp:ListItem>
    <asp:ListItem Text="Active" Value="True"></asp:ListItem>
    <asp:ListItem Text="Inactive" Value="False"></asp:ListItem>

 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        <asp:GridView ID="grdview" runat="server" Width="27%" AutoGenerateColumns="False"

        DataKeyNames="PKID" onrowcommand="grdview_RowCommand">
            <Columns>
                <asp:BoundField DataField="PKID" Visible="false" />
                <asp:BoundField DataField="Query" HeaderText="Query" />
                 <asp:BoundField DataField="Status" HeaderText="Status" />
             <asp:TemplateField HeaderText="Edit/View">
                    <ItemTemplate>
        <asp:ImageButton ID="ibtnResetPWD" runat="server" CausesValidation="False"

 

ImageUrl="~/Images/viewbut.gif" CommandName="View"

         CommandArgument='<%# Eval("PKID") %>'/>
                 </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>





C#



C #

 public void BindGrid()
       {
           using (SqlConnection connection =new SqlConnection(str))
           {
               SqlCommand command = new SqlCommand("usp_BindData", connection);
               command.CommandType = CommandType.StoredProcedure;
               connection.Open();
               DataSet ds = new DataSet();
               SqlDataAdapter adap = new SqlDataAdapter(command);
               adap.Fill(ds);
               grdview.DataSource = ds;
               grdview.DataBind();
           }
       }

protected void grdview_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           if (e.CommandName == "View")
           {
               int rowIndex = ((GridViewRow)((ImageButton)e.CommandSource).NamingContainer).RowIndex;
               int id = Convert.ToInt16(e.CommandArgument);
               using (SqlConnection conn = new SqlConnection(str))
               {
                   SqlCommand cmd = new SqlCommand("usp_GetData", conn);
                   cmd.CommandType = CommandType.StoredProcedure;
                   cmd.Parameters.AddWithValue("@PKID", id);
                   conn.Open();
                   SqlDataAdapter da = new SqlDataAdapter(cmd);
                   DataTable dt = new DataTable();
                   da.Fill(dt);
                   txtQuery.Text = dt.Rows[0]["Query"].ToString();
                   ddlStatus.SelectedValue = dt.Rows[0]["Query"].ToString();
               }

           }
       }





它看起来很冗长,但需要一个简单的逻辑帮助。



It looks lengthy but need help for a simple logic.

推荐答案

更改行来自:
Change the line From:
ddlStatus.SelectedValue = dt.Rows[0]["Query"].ToString();





To:



To:

ddlStatus.SelectedValue = dt.Rows[0]["Status"].ToString();


这篇关于我想在下拉列表中使用DDL中的其他值向用户显示所选值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆