我正在使用如下所述的GridView
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="gvResult" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" onclick="checkAll(this);" />
Remove Lists
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk" runat="server" onclick="Check_Click(this)" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
当我尝试获取按钮上的复选框值时,即使选中复选框,它也始终返回
以下是我的按钮点击事件
protected void btnDeleteLists_Click(object sender, EventArgs e)
{
string str = string.Empty;
foreach (GridViewRow gvrow in gvResult.Rows)
{
CheckBox chk = (CheckBox)gvrow.FindControl("chk");
if (chk != null & chk.Checked)
{
//Some Code
}
}
}
页面加载事件
protected void Page_Load(object sender, EventArgs e)
{
cmdSearch.Text = "Search " + rbSearch.SelectedValue;
if (SessionUtilities.Current_UserType != "3")
{
gvResult.Columns[gvResult.Columns.Count - 3].Visible = false;
}
try
{
if (Request.QueryString["ListType"].ToString().Trim() == "SL") ListType = 2;
if (Request.QueryString["ListType"].ToString().Trim() == "DSL") ListType = 3;
}
catch { }
if (ListType == 2) ListTypeString = "Suppression";
if (ListType == 3) ListTypeString = "Default Suppression";
SessionUtilities.SetTabHeadingDesc("List", ListTypeString + " List Summary", "View summary of your created lists");
this.Title = "(View List) " + System.Configuration.ConfigurationManager.AppSettings["Page_Title"].ToString();
//if (!IsPostBack && !Is)
//{
BindResultGridView();
//}
newDt = GetAllLists();
}
所以我哪里出错了?
答案 0 :(得分:1)
@echo off
setlocal EnableDelayedExpansion
rem Read file2 from redirected input
< file2.txt (
rem Process file1 via FOR /F loop
for /F %%a in (file1.txt) do (
rem If line in file1 is "$test$"
if "%%a" equ "$test$" (
rem Change it by next line in file2
set /P "line2="
echo !line2!
) else (
echo %%a
)
)
)
只需使用//if (!IsPostBack && !Is) //{ BindResultGridView(); //}
就可以了。
说明: - 如果在页面处于回发阶段时再次在页面加载中绑定gridview,它将丢失您上次执行的更改。它将重新初始化整个gridview,因此您的代码无法正常工作。
答案 1 :(得分:0)
你应该使用gridren的prerender事件或rowdatabound事件来获取更新面板中的复选框值