在CheckBox中加载事件,可以用Javascript写
循环只要找到一个CheckBox打勾,就Enable 按钮,否则Disable传递参数可以用隐藏的控件解决
循环只要找到一个CheckBox打勾,就Enable 按钮,否则Disable传递参数可以用隐藏的控件解决
解决方案 »
- 用form.show()显示form之后,不能用tab键切换控件
- 麻烦帮我看看这段代码有什么错,没分,请间量,相互学习
- 请问,处理WM_NCPAINT消息以重画标题栏后,在Vista系统中,标题栏是否仍然透明?谢谢!
- 如何实现矢量图软件?
- 命名空间并不直接包含诸如字段或方法之类的成员
- 如何在还没更新数据库前取得将要使用的用作标识的id的值(sqlsever)
- 为什么没有得到我想要的结果--get{} set{}
- 关于DataGrid
- C#代码如何获取javascript中国的变量值,在线求助
- c#中如何使用api SHGetPathFromIDList???急
- 关于css在datagrid当中的问题。
- 什么是多重数组?
本文所有举例都将使用以下DataGrid:
<asp:DataGrid id="dg" runat="server"
Bordercolor="black"
gridlines="vertical"
font-names="Arial"
font-size="10pt"
HeaderStyle-BackColor="#FFCC00"
ItemStyle-BackColor="#FFCC66"
AlternatingItemStyle-BackColor="#FFFFFF"
AutoGenerateColumns="False">
<Columns>
</Columns>
</asp:datagrid>
以上DataGrid并不能直接使用,我们需要和具体应用结合。在这里,我们主要目的是知道这个DataGrid的一些具体设置情况。
TemplateColumn
我们知道,有很多方法可以显示一些特殊的数据列,比如使用boundcolumns, hyperlinkcolumns等。然而,使用TemplateColumn可以帮助我们实现更多功能,看以下几个举例:
CheckBox / CheckBoxList
CheckBox可以被用于选择一个数据(事情)的状态是真、假等,由于其很直观的使用“勾”和“叉”来表示真、假,所以,往往比一个简单的“Yes”和“No”更加受欢迎。在DataGrid中,我们可以使用CheckBox来实现很好的数据删除功能,首先,我们让访问者选择需要删除的数据,然后在DataGrid的底部提供一个数据删除提交按钮,这样的删除功能用户比较不容易出错。来看一个举例:
<asp:templatecolumn>
<itemtemplate>
<asp:checkbox runat="server" Checked='<%# Container.DataItem("Married") %>' Enabled="False" id="chk1" />
</itemtemplate>
</asp:templatecolumn>
程序执行效果如下:
以上程序中,CheckBox用于显示数据字段Married,如果该数据字段为真,CheckBox为勾;如果为假,CheckBox为叉。我们发现,使用CheckBox来表现数据字段的真假很直观。
RadioButton / RadioButtonList
RadioButton的使用,我们可以参考以下代码:
<asp:templatecolumn>
<edittemplate>
<asp:radiobuttonList runat="server">
<asp:listitem value="Trek">Star Trek</asp:listitem>
<asp:Listitem value="Wars">Star Wars</asp:listitem>
</asp:radiobuttonlist>
</edittemplate>
</asp:templatecolumn>
程序执行效果如下:
什么时候使用TemplateColumns
本文所有举例都使用templatecolumn来显示数据。尽管不是所有数据显示都是使用templatecolumn,但是,当我们需要对DataGrid具有较多控制的时候,就必须使用它。比如,
HyperLink column只许显示一列数据,当我们需要显示更多的时候,就必须使用templatecolumn了,代码如下:
<asp:templatecolumn>
<itemtemplate>
<a href=../view.aspx?id=<%# Container.DataItem("ID") %>><%# Container.DataItem("ID") & Container.DataItem("Name") %></a> </itemtemplate>
</asp:templatecolumn>
程序的严谨最起码也是最常见的就是提交前的数据验证,在DataGrid中使用Web Forms也有这个要求:
<asp:templatecolumn>
<itemtemplate>
<%# Container.DataItem("Age") %>
</itemtemplate>
<edititemtemplate>
<asp:RegularExpressionValidator runat="server" ControlToValidate="txtAge" ErrorMessage="Invalid input for Age"
ValidationExpression="[0-9]{2}" /><br>
<asp:textbox runat="server" id="txtAge" value='<%# Container.DataItem("Age") %>' />
</edititemtemplate>
</asp:templatecolumn>
以上代码要求输入的年龄字段(Age)只能为两位的数字,我们来看执行效果:
上图我们看到,不能通过验证数据将不被提交。
总结
Web Forms在DataGrid中的使用能简化程序界面的复杂程度,提高程序可用性。但是,如果使用不当,反而会增加程序执行时间,占用系统资源。所以,使用的时候,我们应该根据程序特点采用适当方式。
http://www.detech.com.cn/labv20/bank/bank_confirm.asp
这个就是所需要实现功能的界面
但是我需要用c#编写 能说详细点吗?谢谢了:)
private void tb_delete_Click(object sender, System.EventArgs e)
{
module.WantInfolog.WantInfologDetail cs_br=new module.WantInfolog.WantInfologDetail();
string sql="";
string id;
bool checkeds=false;
foreach(DataGridItem dgi in DataGrid1.Items)
{
CheckBox cb=(CheckBox)(dgi.Cells[0].Controls[1]);
if (cb.Checked==true)
{
int d= dgi.ItemIndex;
id = DataGrid1.DataKeys[d].ToString();
sql+=id+",";
checkeds=true;
module.WantInfolog.WantInfologDetail cs_wantlog=new module.WantInfolog.WantInfologDetail(Convert.ToInt32(id));
module.publicsub pub=new module.publicsub();
string jobid=cs_wantlog.get_WantInfoid;
string userid=cs_wantlog.get_PersonalInfoid;
string compid=Session["id"].ToString();
Response.Write(pub.popupWindowsMax("test/hjemail.asp?compid="+compid+"&jobid="+jobid+"&userid="+userid));
cs_wantlog=null;
}
}
if(checkeds)
{
int sqllength=sql.Length;
if(sql.Substring(sqllength-1,1).Equals(","))
cs_br.SB_update_info(sql.Substring(0,sql.Length-1));
else
cs_br.SB_update_info(sql);
Response.Write("<script language=javascript>alert('您选择的人员已成功放入垃圾桶!');window.location='WantInfoManager.aspx';</script>");
}
else
Response.Write("<script language=javascript>alert('您没有选择任何人员!');</script>");
}
[j].FindControls("CheckBox1");
注意:由于作用域的关系CB应声明为全局。在CheckBox1 的CheckedChanged事件中
this.button1.Visible=true;
this.button1.Visible=true;
自己测试