当前位置: 首页>>代码示例>>C#>>正文


C# ImageButton.Focus方法代码示例

本文整理汇总了C#中System.Web.UI.WebControls.ImageButton.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# ImageButton.Focus方法的具体用法?C# ImageButton.Focus怎么用?C# ImageButton.Focus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.UI.WebControls.ImageButton的用法示例。


在下文中一共展示了ImageButton.Focus方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ToggleRepeaterControl

        /// <summary>
        /// Toggles css styles and readonly attributes for given repeater
        /// </summary>
        /// <param name="list">Repeater</param>
        /// <param name="e">RepeaterCommandEventArgs</param>
        public static void ToggleRepeaterControl(Repeater list, RepeaterCommandEventArgs e)
        {
            string cname = e.CommandName.ToString();                                        // command name
            string listid = list.ID;                                                        // id of the repeater
            string controltype;                                                             // control type
            string controlname;                                                             // name of the control
            int i = e.Item.ItemIndex;                                                       // row index
            ImageButton btn = new ImageButton();

            if (cname == "edit")
            {
                // lock all rows except selected index
                for (int j = 0; j < list.Items.Count; j++)
                {
                    // hide edit button
                    btn = (ImageButton)list.Items[j].FindControl("btnE" + listid);
                    btn.Visible = false;

                    // hide delete button
                    btn = (ImageButton)list.Items[j].FindControl("btnD" + listid);
                    btn.Visible = false;
                }

                // toggle TextBox and CheckBox
                for (int j = 0; j < list.Items[i].Controls.Count; j++)
                {
                    // get control type and name
                    controltype = list.Items[i].Controls[j].GetType().ToString();
                    controlname = list.Items[i].Controls[j].ClientID.ToString();

                    // check for textboxes that are not tagged as "readonly"
                    if (controltype.Contains("TextBox") && !controlname.Contains("readonly"))
                    {
                        ((TextBox)list.Items[i].Controls[j]).CssClass = "editable";
                        ((TextBox)list.Items[i].Controls[j]).ReadOnly = false;
                        ((TextBox)list.Items[i].Controls[j]).Focus();
                    }
                    // check for checkboxes that are not tagged as "readonly"
                    else if (controltype.Contains("CheckBox") && !controlname.Contains("readonly"))
                        ((CheckBox)list.Items[i].Controls[j]).Enabled = true;
                    // check for dropdownlists (dropdownlists cannot be tagged as "readonly"
                    else if (controltype.Contains("DropDownList"))
                    {
                        ((DropDownList)list.Items[i].Controls[j]).CssClass = "editable";
                        ((DropDownList)list.Items[i].Controls[j]).Enabled = true;
                    }
                }

                // change edit --> update button
                btn = (ImageButton)list.Items[i].FindControl("btnE" + listid);
                btn.ImageUrl = "~/images/update.png";
                btn.Visible = true;
                btn.CommandName = "update";

                // change delete --> cancel button
                btn = (ImageButton)list.Items[i].FindControl("btnD" + listid);
                btn.ImageUrl = "~/images/cancel.png";
                // show button, as button is hidden in reportListPage
                btn.Visible = true;
                btn.CommandName = "cancel";

            }
            else if ((cname == "cancel") || (cname == "update"))
            {
                // toggle TextBox and CheckBox
                for (int j = 0; j < list.Items[i].Controls.Count; j++)
                {
                    controltype = list.Items[i].Controls[j].GetType().ToString();
                    if (controltype.Contains("TextBox"))
                    {
                        ((TextBox)list.Items[i].Controls[j]).CssClass = "readonly";
                        ((TextBox)list.Items[i].Controls[j]).ReadOnly = true;
                    }
                    else if (controltype.Contains("CheckBox"))
                        ((CheckBox)list.Items[i].Controls[j]).Enabled = false;
                    //else if (controltype.Contains("DropDownList"))
                    //{
                    //    ((DropDownList)list.Items[i].Controls[j]).CssClass = "readonly";
                    //    ((DropDownList)list.Items[i].Controls[j]).Enabled = false;
                    //}
                }
            }
            else if (cname == "delete")
            {
                // lock all rows except selected index
                for (int j = 0; j < list.Items.Count; j++)
                {
                    // hide edit button
                    btn = (ImageButton)list.Items[j].FindControl("btnE" + listid);
                    btn.Visible = false;

                    // hide delete button
                    btn = (ImageButton)list.Items[j].FindControl("btnD" + listid);
                    btn.Visible = false;
                }
//.........这里部分代码省略.........
开发者ID:DanielSpalding,项目名称:Projects,代码行数:101,代码来源:UIManager.cs


注:本文中的System.Web.UI.WebControls.ImageButton.Focus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。