<asp:datagrid id="DataGrid_BanZu" runat="server" Width="648px" Height="96px" BorderStyle="Solid"
ToolTip="双击某条记录可以进行修改" ForeColor="White" CellPadding="4" BackColor="White" BorderWidth="1px"
BorderColor="Gray" AllowSorting="True" PageSize="5" AllowPaging="True" AllowCustomPaging="True"
AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="Aqua" BackColor="Khaki"></SelectedItemStyle>
<EditItemStyle BackColor="Blue"></EditItemStyle>
<AlternatingItemStyle CssClass="DataGrid_AlternatingItem"></AlternatingItemStyle>
<ItemStyle CssClass="DataGrid_Item"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" BorderWidth="5px" ForeColor="Black" BackColor="Orange"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="选中">
<HeaderStyle HorizontalAlign="Center" Width="50px"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:CheckBox id="chkExport" AutoPostBack="False" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ID" HeaderText="编号">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="班组名称">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Description" HeaderText="描述信息">
<HeaderStyle Width="40%"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle Visible="False" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
代码如下:
System.Web.UI.WebControls.CheckBox chkExport;
string strDel = "DELETE FROM tbl_BASE_TEAM WHERE ID = ";
int iCount = 0;
foreach(DataGridItem oDataGridItem in DataGrid_BanZu.Items)
{
chkExport = (CheckBox)oDataGridItem.FindControl("chkExport");
//Response.Write(Convert.ToString(chkExport.Checked));
TextBox_Description.Text += Convert.ToString(chkExport.Checked); if(chkExport.Checked)
{
if(iCount == 0)
{
strDel += oDataGridItem.Cells[1].Text.ToString();
}
else
{
strDel += " OR ID = ";
strDel += oDataGridItem.Cells[1].Text.ToString();
}
iCount++;
//((HtmlInputHidden)oDataGridItem.FindControl("SelectedID")).Value;
}
}我发现即便在datagrid中选中整个checkbox,
但是在if(chkExport.Checked) 语句中也总是返回false。
请问这是为什么?
谢谢。
ToolTip="双击某条记录可以进行修改" ForeColor="White" CellPadding="4" BackColor="White" BorderWidth="1px"
BorderColor="Gray" AllowSorting="True" PageSize="5" AllowPaging="True" AllowCustomPaging="True"
AutoGenerateColumns="False">
<SelectedItemStyle Font-Bold="True" ForeColor="Aqua" BackColor="Khaki"></SelectedItemStyle>
<EditItemStyle BackColor="Blue"></EditItemStyle>
<AlternatingItemStyle CssClass="DataGrid_AlternatingItem"></AlternatingItemStyle>
<ItemStyle CssClass="DataGrid_Item"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" BorderWidth="5px" ForeColor="Black" BackColor="Orange"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="选中">
<HeaderStyle HorizontalAlign="Center" Width="50px"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:CheckBox id="chkExport" AutoPostBack="False" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ID" HeaderText="编号">
<HeaderStyle Width="10%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="班组名称">
<HeaderStyle Width="40%"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Description" HeaderText="描述信息">
<HeaderStyle Width="40%"></HeaderStyle>
</asp:BoundColumn>
</Columns>
<PagerStyle Visible="False" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
代码如下:
System.Web.UI.WebControls.CheckBox chkExport;
string strDel = "DELETE FROM tbl_BASE_TEAM WHERE ID = ";
int iCount = 0;
foreach(DataGridItem oDataGridItem in DataGrid_BanZu.Items)
{
chkExport = (CheckBox)oDataGridItem.FindControl("chkExport");
//Response.Write(Convert.ToString(chkExport.Checked));
TextBox_Description.Text += Convert.ToString(chkExport.Checked); if(chkExport.Checked)
{
if(iCount == 0)
{
strDel += oDataGridItem.Cells[1].Text.ToString();
}
else
{
strDel += " OR ID = ";
strDel += oDataGridItem.Cells[1].Text.ToString();
}
iCount++;
//((HtmlInputHidden)oDataGridItem.FindControl("SelectedID")).Value;
}
}我发现即便在datagrid中选中整个checkbox,
但是在if(chkExport.Checked) 语句中也总是返回false。
请问这是为什么?
谢谢。
解决方案 »
- textbox显示数据
- js填充的下拉框后台取值问题
- 一模一样的代码,为什么服务器上和本地显示的不一样?
- 高分求解!!!很难!!!
- 有关及时通讯的问题
- 虔心请教关于应用程序输出到HTTP的问题
- 怎样在网页中捕获键盘消息,并且不引起防火墙报警?
- 我想在javascript语句中使用for each语句把form中的所有radio都变得不可用,不知怎么写
- 怎么实现dropdownlist在页面间的传递
- 在线,请问为什么我的程序每次连接数据库的时候,一个还可以,同时两个就总是失败?
- 一个基础问题:如果我有多个页面要判断用户是否登陆没有,用什么方法最好?
- ajax 怎样从javascript传一个字符串数组到ajax,ajax怎样接收。返回都是null值。不知为何。
{
....;// 绑定DataGrid
}
请问这个if(!Page.IsPostBack)到底是干什么的?
谢谢。
有这个变量..
如果checkbox在datagrid中的第一列的话
dim ck as new checkbox
ck=ctype(c.item.cell(0).findcontrol,checkbox)
if (ck.checked)
///处理
end if
这样就行了
解释一下if(!page.ispostback){}:
ifpostback:回发(相当于第一次加载页面)
protected void btnDel_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < this.gvSelfHelpPublicShare.Rows.Count; i++)
{
if (((CheckBox)this.gvSelfHelpPublicShare.Rows[i].Cells[0].Controls[1]).Checked == true)
{
SelfHelpPublicShareID = UtilTool.ToSafeInt32(this.gvSelfHelpPublicShare.DataKeys[i].Value); new SelfHelpPublicShareManager().DeleteSelfHelpPublicShareByID(SelfHelpPublicShareID);
}
}
this.BindPageIndex(1);
} catch (Exception ex)
{
this.lblMessage.Text = ex.Message;
}
}
if (((CheckBox)this.gvSelfHelpPublicShare.Rows[i].Cells[0].Controls[1]).Checked == true)
判断是否选中!
if(!Page.IsPostBack)
{
....;// 绑定DataGrid
}搞定了