Need to be able to display a record from a database or allow a user to select a record from a gridview then you basically have two control options the detailsview control and the formview control.
The detailsview is the quick and dirty way of display a list of fields and there corresponding values. It gives you the ability to delete, edit and create records in a nice simple top to bottom display. In making a quick editing form there couldn't be an easier way. But lets say you need to customize how the record is displayed to the user. A couple of rows? Need the custom form handling or AJAX? The detailsview will fall short. Enter the Formview
The formview is much like the detailsview in that it handles the display of a single databound record to the user for delete, edit or create but gives the developer the ability to customize how the user sees the data in the form of templates. When a datasource is bound to a formview a generic set of templates is created for the display, edit and insert states. A developer can arrange or customize these templates to meet any requirements for customized field display.
In the next view post I will be examining the formview and all it has to offer.
-cj
Friday, April 25, 2008
Wednesday, October 3, 2007
Open window from ASP.NET GridView control select event
Opening a new window from the select event of an ASP.NET GridView control can be a real life saver when needing to display the results of a row selection in a new user window.
With a little code behind and some javascript no problemo.......
Using the GridView SelectedIndexChanged event
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
As part of the ASP.NET GridView you have access to the Gridview.SelectRow property. Not to be confused with a DataRow the GridViewRow returned is just a collection of the cells in the table made up for that particular row. No columns or searchs based on field name or anything like that :(
This is particularly helpful if you want to grab things to pass to the new window as part of the querystring like ID's or other unique identifiers.
So now we can add some code to grab some of the values.
Remember that these are integer based cell call 0-n~
Back to the task at hand
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
With a little code behind and some javascript no problemo.......
Using the GridView SelectedIndexChanged event
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
End Sub
As part of the ASP.NET GridView you have access to the Gridview.SelectRow property. Not to be confused with a DataRow the GridViewRow returned is just a collection of the cells in the table made up for that particular row. No columns or searchs based on field name or anything like that :(
This is particularly helpful if you want to grab things to pass to the new window as part of the querystring like ID's or other unique identifiers.
So now we can add some code to grab some of the values.
Remember that these are integer based cell call 0-n~
Back to the task at hand
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim selectedRow as GridViewRow = GridView1.SelectedRow
Dim myID as string = selectedRow.Cells(1).Text
Response.Write("<script language=""javascript"">window.open('default.aspx?recno=" + myID + "');</script>")
End Sub
Notice that we are getting the value of the 2nd cell (selectedRow.Cells(1) from a zero based array) and passing a javascript line that is wrote on the close of the page. This will allow pass values between pages in your ASP.NET application fired from the Select event of a GridView.
This will know fire a new window with the arguement "recno" in the request string.
Aint ASP.NET grand?
-CJ
Subscribe to:
Comments (Atom)