c# - Asp.net 日历控件中的 DropDownList

标签 c# asp.net .net vb.net

是否可以在 asp.net Calendar 控件的日历日内添加 DropDownList,然后将其绑定(bind)到 SelectedIndexChanged事件?

我可以在我想要的日期内添加 DropDownList,但我一直无法将它绑定(bind)到事件。我已经看到它为 Calendar 控件中的 LinkBut​​ton 完成了,但没有为 DropDownList 完成。

最佳答案

你也可以这样做。将您的数据放入一个对象变量中,然后将其数据转换为选择标签(html 中的下拉列表标签),然后将该控件添加到日历中。

protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
    stringBuilder matrix = new stringBuilder();
    var SemList = (from row in dt.AsEnumerable()                                    
                  select new
                  {
                   SemName = row.Field<string>("SemName"),
                   SemID = row.Field<string>("SemID")
                  });

    if (SemList != null)
    {
        Matrix.Append("<select ID='sem_" + dt.Rows[k]["ActualCMID"].ToString() + "' runat='server' width='100px' onchange='" + Server.HtmlEncode("javascript:BindSpecialization('" + dv.ToTable().Rows[k]["ActualCMID"].ToString() + "')").ToString() + "'>");
        Matrix.Append("<option value='0'>---Select---</option>");
        foreach (var sem in SemList)
        {
           Matrix.Append("<option value='" + sem.SemID + "'>" + sem.SemName + "</option>");
        }
        Matrix.Append("</select>");
    }
    e.Cell.Controls.Add(new LiteralControl(Matrix.ToString()));
}

希望对您有所帮助。

关于c# - Asp.net 日历控件中的 DropDownList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7851658/

相关文章:

c# - 从类库转换为 WCF 需要采取哪些步骤?

javascript - 从 JavaScript WebMethod 访问单独的 C# 文件

c# - 显式打开时上下文菜单不显示绑定(bind)项目(通过 ContextMenu.IsOpen)

c# - 为什么我在打开连接时收到 "Invalid attempt to call HasRows when reader is closed"?

c# - HttpHeaders.TryAddWithoutValidation 是否验证?

c# - Windows Mobile 中的 Flash SMS

c# - 通过 Cruise Control 发布 MVC v1 C# 应用程序

asp.net - ASP.NET MVC 5表单验证和错误处理

c# - 如何阻止某些 ip(用户)访问我的网站?

c# - 在没有访问权限和 key 的情况下上传到 Amazon S3