设置下拉框的初始值:
<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(" "," ");
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=" "
}
}