知识 经验的积累

来源:互联网 发布:苹果mac最新版本 编辑:程序博客网 时间:2024/04/24 21:59

 

--------------------------------------------------------------------------------------------

1。GridView 常用功能:

获取模版列中 ID 与 TextBox 值:

int categoryID = (int)GvGradeType.DataKeys[e.RowIndex].Value;
TextBox NewName 
= (TextBox)GvGradeType.Rows[e.RowIndex].FindControl("控件ID");

 

按钮实现GridView编辑,更新,删除,取消功能。

分别设置CommandName ,

编辑--CommandName="Edit",对应事件 RowEditing ,--(GridVier1.EditIndex = e.NewEditIndex;)

在编辑事件中查找 DropDownList 控件的例子,并指定 DataKeys 中选择的字段内容!~ (先绑定数据在查找字段)

DropDownList NewName= (DropDownList)GvFamily.Rows[e.NewEditIndex].FindControl("控件ID");

NewName.SelectedValue 
= GvFamily.DataKeys[e.NewEditIndex][1].ToString();

更新--CommandName="Update",对应事件 RowUpdating

删除--CommandName="Delete",对应事件 RowDeleting

取消--CommandName="Cancel" ,对应事件 RowCancelingEdit,--(GridVier1.EditIndex = -1;)

替换--GridView 中的字体,对应事件 RowDataBound ,--对应的例子!~ 也可以写个对应的类替换!

protected void GvCourseset_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblNewSing 
= (Label)e.Row.FindControl("lblSign");
            
if (lblNewSing != null)
            {
                
if (lblNewSing.Text == "1")
                {
                    lblNewSing.Text 
= "";
                }
                
else
                {
                    lblNewSing.Text 
= "";
                }
            }
        }
    }

 

----------------------------------------------------------------------------------------

2。弹出删除确认,在Onclice

OnClientClick="return confirm('您确认删除该记录吗?');"

----------------------------------------------------------------------------------------

3。DropDownList 控件改变索引 当前文本框获取 DropDownList 内的值(客户端无刷新)

<asp:DropDownList ID="ddlGradeid" runat="server" onchange="setvalue(this)">
            
</asp:DropDownList>

function setvalue(slt)
    {
        document.form1.txtName.value 
= slt.options[slt.selectedIndex].text;
    }

<input id=txtName type=text name=name size=12 runat="server" maxlength="64" >

 

----------------------------------------------------------------------------------------

4。隐藏Html文本框,使用说明(获取值到文本框,但是文本框不显示出来)

<input id="techid" runat="server" name="techid" type="hidden" />

----------------------------------------------------------------------------------------

 5。JS查找Html控件。(因为Lable生成的Html控件不是表单控件)

var num = document.all("lblNum").innerHTML;
<asp:Label ID="lblNum" runat="server"></asp:Label>

-----------------------------------------------------------------------------------------

6。判断页面是否传值-

if (Request["techid"== "" || Request["techid"== null)
            {
                Response.Write(
"没有传该值");
            }
            
else
            {
                
//传值了可以引用
                techid = Request.QueryString["techid"].ToString();
            }

------------------------------------------------------------------------------------------

7。DataList 中替换,查找模板列中的控件!

Literal lbluser = (Literal)e.Item.FindControl("lbluser");
        
if (lbluser != null)
        {
            lbluser.Text 
= "要替换的字符!";
        }

--------------------------------------------------------------------------------------------

8。伪页面。picknews-1.aspx(伪) pick.aspx?id=1(真)

<a href="picknews-<%# Eval("pub_id") %>.aspx">
 Web.Config中配置
<RewriterConfig>
        
<Rules>
            
<!-- 重写规则-->
            
<RewriterRule>
                
<!--要实现的url格式-->
                
<LookFor>~/picknews-(d{1,6}).aspx</LookFor>
                
<!--真实的url地址.$1.$2,$3...$N代表正则匹配的第N个表达式-->
                
<SendTo>~/pick.aspx?id=$1</SendTo>
            
</RewriterRule>
        
</Rules>
    
</RewriterConfig>

 

原创粉丝点击