question

ScotKing-6706 avatar image
0 Votes"
ScotKing-6706 asked AlbertKallal-4360 edited

Bind Gridview without causing postback

I don't know why they closed forums.asp.net after so many years. Anyways, hopefully I hope to see other posters from that site over here!

I have a page with about 10 gridviews on it. Each one has a modal popup extender. On one of them I have added a column at the far left with a checkbox. in the gridview. I have javascript code that you can only select one of the checkboxes in the gridview. I'm using postback =true for the checkbox and the oncheckbox changed event handler to popuplate the grideview directly below the gridvew. When you check one of the boxes in gridview 5, it populates the gridview 6 directly below it with income information which is tied to the employer ID in the gridview 5.

There are a couple of of issues. On initial page load, the gridview 5 loads with employer data. As long as there is one row, the checkbox should be checked on the left. How is this done? In the page load event? In Rowdatabound event? When this happens, the gridview below (gridveiew 6) should load with the income that is tied to the employer in the above gridview. There can be several types of income an employer in the above gridview. I'm using the empid datakey from gridview 5 to store into a column in the income database.

Is there a way to update the gridview 6 without causing a postback? So when you check a box in gridview 5, there is no page refresh.

Protected Sub ChckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim row As GridViewRow = TryCast((CType(sender, Control)).Parent.NamingContainer, GridViewRow)
Dim key As String = GridView5.DataKeys(row.RowIndex).Value.ToString()
Dim Incomeadapter As New DataSet1TableAdapters.IncomeTableAdapter
Dim tblincome As New DataSet1.IncomeDataTable
tblincome = Incomeadapter.GetData(key)
GridView6.DataSource = tblincome
GridView6.DataBind()
End Sub


dotnet-aspnet-webforms
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You can put the grid view in a up-date panel. That way you not see a page re-fresh and only the grid will re-plot + display. This is MUCH less work then trying to now adopt js code, and doing this 100% client side. And you not get much more performance anyway.

however, I don't think the child grids need to be loaded up until such time you click/check that box. Take a look at this recent example posted where I nest a child grid view inside of a listview (and I explain why i used for the main grid a listview as opposed to a gridview. But the child expanding (exploding view) does use gridviews.


Now I use a simple regular button as opposed to a check box - but when I expand (or collapse) the view, the state of that setting remains in place:

Example here:

how-i-show-a-nested-dataview.html





0 Votes 0 ·

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered

Hi @ScotKing-6706 ,
If you don't want to refresh,you could use updatepanel. Child controls of the panel cause an asynchronous postback.
https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.updatepanel?view=netframework-4.8
Best regards,
Yijing Sun


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.