Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I` making board using GridView.

And now, I want to make like this :

1. If Checkbox is checked in GridView and click modify Button, open popup windows

2. Else alert message 'Please check your item'

I clicked the button below code, When I choose nothing, alert message showed,

and I checked checkbox and press button, also alert message showed.not opened popup

window.

But instead of javascript , if I use code
C#
Response.Redirect("UserBoard_Edit.aspx?BoardItemID=" + boardItemID);

it works well.

I don`t know why It`s not fired...

Is it possible making one javascript function?

Please help me.....

What I have tried:

--- This is .aspx page ---
C#
<asp:LinkButton ID="lnbEdit" runat="server" Text="Edit" OnClick="lnbEdit_Click">

<asp:GridView ID="grvList" DataKeyNames="BoardItemID" runat="server" AutoGenerateColumns="False" >
    <columns>
        <asp:BoundField HeaderText ="boardItemID" DataField="BoardItemID" HeaderStyle-CssClass="hidden">
             <itemstyle cssclass="hidden" />
        
        <asp:BoundField HeaderText="conNo" Visible="false" DataField="indexNo" />
        <asp:TemplateField>
             <itemtemplate>
                 <asp:CheckBox ID="chk" runat="server"/>
             </itemtemplate>
         ...
...
        
        </columns>

--- This is code behind page ---
C#
protected void lnbEdit_Click(object sender, EventArgs e)
  {
      foreach (GridViewRow gRow in grvList.Rows)
      {
          CheckBox chk = (CheckBox)gRow.FindControl("chk");
          if (chk.Checked)
          {
              int boardItemID = Convert.ToInt32(gRow.Cells[0].Text);
              string popURL = "UserBoard_Edit.aspx?BoardItemID=" + boardItemID;
              string openPopUp = @"
              <script type='text/javascript'>
                  popup = window.open('" + popURL + "', 'open_window', 'width = 880, height = 500, left = 0, top = 0'); popup.focus();</script>";
              this.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", openPopUp);
              //Response.Redirect("UserBoard_Edit.aspx?BoardItemID=" + boardItemID);
          }
          else
          {
              string message = @"
              <script type='text/javascript'>
                  alert('Please check your Item');
              </script>";
              this.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", message);
          }
      }
  }
Posted
Updated 24-Aug-16 1:29am
v6

1 solution

Quote:
and I checked checkbox and press button, also alert message showed.not opened popup window.


It seems that your CheckBox Checked property always returns false. Have you tried debugging your code?

To ensure that the CheckBox state will not reset on each and every postback, then you must bind your GridView within Not IsPostback block in Page_Load event:

C#
protected void Page_Load(object sender, EventArgs e){
        if (!IsPostBack)
        {
            //Bind Your GridView Here
        }
}
 
Share this answer
 
Comments
RydenChoi 25-Aug-16 0:21am    
Thanks your comment Vincent, but I already did it.
I think modify javascript to one code and fix c# code...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900