Populate text boxes with data based on redirect from another page
This task is a little out of my reach 开发者_C百科so i dont even really know where to start...
I want a user to click the command field "select" in my gridview. I then want them to be redirected ( response.redirect()
) to an input form that will have its various asp.net text boxes filled with data from that selected item.
I also need the ability to do this logical process:
IF the form is loaded from user selecting item in gridview THEN ''Populate controls with data from selected gridview item Else Load form as normal and have the controls blank endif
I was suggested to use this command for the redirect load...Not sure if its correct:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If InStr(Request.ServerVariables("HTTP_REFERER"), "LogViewer.aspx") Then
'FILL the text boxes with the data from data source!
End If
End Sub
+++++++++++++++++++++++++++++++++++++++++++++++++++++++ EDIT
I got it working thanks to A Tuliper...now how can i get my drop down list to select the correct item based on the data in the gridview??
Private Sub getData(ByVal user As String)
Dim dt As New DataTable()
Dim connection As New SqlConnection("My Connection ")
connection.Open()
Dim sqlCmd As New SqlCommand("SELECT * from AppMaster WHERE RecNum = @recnum", connection)
Dim sqlDa As New SqlDataAdapter(sqlCmd)
sqlCmd.Parameters.AddWithValue("@recnum", user)
sqlDa.Fill(dt)
If dt.Rows.Count > 0 Then
NameTxt.Text = dt.Rows(0)("UserName").ToString()
'''''''''this drop down list needs to be the correct item'''''''''''''''''
'AppDropDownList.SelectedValue = dt.Rows("Application").ToString()
SelectedDateTxt.Text = dt.Rows(0)("DateOfChange").ToString()
DescriptionTxt.Text = dt.Rows(0)("Description").ToString()
SnipetTxt.Text = dt.Rows(0)("Snippet").ToString()
End If
connection.Close()
End Sub
The easiest unhacky method here is to simply create a link in your gridview with the parameters in the URL going to say:
<a href="/YourSecondPage.aspx?param1=xx¶m2=yyyy">Details</a>
And then in your second page read them:
string param1 = Request.QueryString["Param1"]; //or whatever its called - change it of course
精彩评论