在同一页面的网格中显示下拉列表选定值

时间:2012-09-10 13:34:43

标签: c# asp.net gridview drop-down-menu asprepeater

我有一个下拉列表,其中包含代表列表。当用户选择一个委托时,我使用第一个下拉列表中的selectedindexchange事件填充第二个下拉列表中的可用会议时间 Aspx页面

<asp:DropDownList ID="delegate_ddl" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddldelegates_SelectedIndexChanged" Width="200px"></asp:DropDownList>
<asp:DropDownList ID="delegatetime_ddl" runat="server" Width="90px"></asp:DropDownList>
<asp:Button ID="adddelegate" runat="server" Text="Add" onclick="adddelegate_Click"/>

.cs页面

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataSet ds1 = getdata.getdelegatelist();
                delegate_ddl.DataSource = ds1.Tables[0];
                delegate_ddl.DataTextField = "DELEGATE_NAME";
                delegate_ddl.DataValueField = "DELEGATE_ID";
                delegate_ddl.DataBind();
                delegate_ddl.Items.Insert(0, "--Select--"); 
            }

        }
        protected void ddldelegates_SelectedIndexChanged(object sender, EventArgs e)
        {
            string delselection = delegate_ddl.SelectedValue.ToString();
            DataSet ds2 = getdata.getdelegatetimelist(delselection);
            if (ds2.Tables[0].Rows.Count > 0)
            {
                delegatetime_ddl.DataSource = ds2.Tables[0];
                delegatetime_ddl.DataTextField = "TIMESLOT";
                delegatetime_ddl.DataValueField = "TIMEID";
                delegatetime_ddl.DataBind();
            }
            else
            {
                time_lbl.Text = "No slots Open";
            }
        }
        protected void adddelegate_Click(object sender, EventArgs e)
        {
            string delegateselected = delegate_ddl.SelectedValue.ToString();
            string timeslotselected = delegatetime_ddl.SelectedValue.ToString();
            getdata.delegatemeetinsert(personidd, delegateselected, timeslotselected);
        }

现在插入了数据 - 但我的问题是 一旦用户单击添加按钮,我想显示所选的委托和在某种网格视图或下面的动态表中使用删除选项选择的时间段。 有人可以在C#中提供代码示例以实现上述

1 个答案:

答案 0 :(得分:0)

不使用Gridview来显示数据,而是使用像Labels这样的基本控件,它将减少大量不必要的代码。使用Asp.net'Panel'控件并将所有标签和按钮(用于删除目的)封装到Panel中,然后根据需要隐藏/显示。这是可能对您有帮助的代码大纲,

if(!page.IsPostBack) // This goes into Page_Load
{
Panel1.Visible=false;
}

protected void adddelegate_Click(object sender, EventArgs e)   // add this additional code
{
Panel.Visible=True;
GetDelegate()// This method retrieve the delegate you inserted..
Lable1.Text= "Set here Delegate name you just Retrieved"
Label2.Text="Delegate time you retrived"
}

protected void BtnRemovedelegate_Click(object sender, EventArgs e)

{
string Personidd= retrieve person id
string delegateName= Lable1.text;
String timeslot=Label2.Text
SomeDeleteMethod(personidd, delegateName, timeslot); 
Panel1.Visible=false;
}

希望你明白这一点......