ASP.NET代码片段

设置下拉框的初始值:

  <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem Text="小学" Value="1"></asp:ListItem>
        <asp:ListItem Text="中学" Value="2"></asp:ListItem>
        <asp:ListItem Text="大学" Value="3"></asp:ListItem>
        </asp:DropDownList>

 

 string init = "2";
            for (int i = 0; i < DropDownList1.Items.Count; i++)
            {
                if (DropDownList1.Items[i].Value.ToString() == init)
                {
                    DropDownList1.Items[i].Selected = true;
                }
            }

  
 DropDownList1.Items.Insert(0,new ListItem("选择类别",0));

 

<asp:GridView ID="GridView1" ShowFooter="false" BorderColor="Black" OnRowDataBound="GridView1_RowDataBound"  runat="server" AutoGenerateColumns="False"  Font-Size="12px" Width="549px"  AllowPaging="True" >
          <Columns>
            <asp:BoundField DataField="ID" HeaderText="编号" />
             <asp:BoundField DataField="EmpBirthday" HeaderText="生日" DataFormatString="{0:yyyy-MM-dd}" HtmlEncode="False" />
            <asp:BoundField DataField="EmpSalary" HeaderText="薪水" DataFormatString="{0:c}" HtmlEncode="False" />
          </Columns>
          <HeaderStyle BackColor="Azure" Font-Size="12px" HorizontalAlign="Center" />
          <RowStyle HorizontalAlign="Center" />
          <PagerStyle HorizontalAlign="Center" BackColor="#FFFFCC" BorderStyle="None" BorderWidth="0px" ForeColor="#330099" />
            <PagerSettings Visible="False" />
        </asp:GridView>

 

GridView1.DataSource = myds;
        GridView1.DataKeyNames = new string[] { "ID" };
        GridView1.DataBind();

 

  /// <summary>
    /// 当复选框被点击时发生
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
    {
        for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
        {
            CheckBox cbox = (CheckBox)(GridView1.Rows[i].FindControl("CheckBox1"));
            if (CheckBox2.Checked == true)
            {
                cbox.Checked = true;
            }
            else
            {
                cbox.Checked = false;
            }
        }
    }

 

读取文本文件

string   ff=Server.MapPath("/test.txt");  
  StreamReader   sr=   new   StreamReader((ff),Encoding.Default);  
  string   ReadFile1=Sr1.ReadToEnd();  
  try{  
                ReadFile1   =   ReadFile1.Replace("   ","&nbsp;");  
                  textbox1.Text+=ReadFile1;   
  sr.Close();  
}catch(Exception e){};

 

//gridview 行绑定时某列的值

if (e.Row.RowType==DataControlRowType.DataRow)

{

    System.Data.DataRowView drv=(System.Data.DataRowView)e.Row.DataItem;

if(e.Row.DataItem!=null)

//表单被使用过,就不能删除

{drv.Row.ItemArray[1].ToString()=="1"}

{

   e.Row.Cells[e.Row.Cells.Count-3].Text="&nbsp;"

}

 

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值