I have a gridview and data will be populated into the gridview after a Search button is clicked. Inside the gridview there is a checkbox column, then onclick of a Download button I will loop through the checked rows and get the fileName before download all
the checked. The problem is when I clicked this Download button a postback occured and I think this caused the gridview to be empty thus the looping checked rows not working.
However this worked locally but when published as real website with https it is not working.
I have a gridview and data will be populated into the gridview after a Search button is clicked. Inside the gridview there is a checkbox column, then onclick of a Download button I will loop through the checked rows and get the fileName before download all
the checked. The problem is when I clicked this Download button a postback occured and I think this caused the gridview to be empty thus the looping checked rows not working.
However this worked locally but when published as real website with https it is not working.
According to your code, I create a sample using the following code, it seems that everything works well on my side, I could get the selected row values.
protected void Download_Button(object sender, EventArgs e)
{
var Filename = new List<string>();
foreach (GridViewRow gr in GridView1.Rows)
{
CheckBox cb = (CheckBox)gr.FindControl("CheckBox1");
if (cb!=null && cb.Checked)
{
string FileID = GridView1.DataKeys[gr.RowIndex]["FileID"].ToString();
string FileName = gr.Cells[0].Text;
if (FileName != "")
{
//count++;
Filename.Add(FileID +"---"+ FileName);
}
}
//count++;
}
lblresult.Text = "Selected file:" + string.Join(";", Filename);
// Download(Filename);
}
The screenshot as below:
So, I suggest you could re-test your application, if still not working, you could share the whole code (include the paging and checkbox click event), so that we could test it on our side.
Best regards,
Dillion
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
None
0 Points
4 Posts
How to restraint gridview data and get checked value on rows of gridview after postback
Oct 25, 2018 05:10 AM|xchaax|LINK
I have a gridview and data will be populated into the gridview after a Search button is clicked. Inside the gridview there is a checkbox column, then onclick of a Download button I will loop through the checked rows and get the fileName before download all the checked. The problem is when I clicked this Download button a postback occured and I think this caused the gridview to be empty thus the looping checked rows not working.
However this worked locally but when published as real website with https it is not working.
Any help is greatly appreciated.
my code behind
All-Star
45489 Points
7008 Posts
Microsoft
Re: How to restraint gridview data and get checked value on rows of gridview after postback
Oct 26, 2018 06:05 AM|Zhi Lv - MSFT|LINK
Hi xchaax,
According to your code, I create a sample using the following code, it seems that everything works well on my side, I could get the selected row values.
The screenshot as below:
So, I suggest you could re-test your application, if still not working, you could share the whole code (include the paging and checkbox click event), so that we could test it on our side.
Best regards,
Dillion
All-Star
52523 Points
15677 Posts
Re: How to restraint gridview data and get checked value on rows of gridview after postback
Oct 26, 2018 06:58 AM|oned_gk|LINK
If it worked locally, i guess the problem is related to accessing the file, such as wrong path or security issue
Suwandi - Non Graduate Programmer