|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagrid/SQL & passing valuesHi,
I am a total ASP virgin and over the pst few nights have written a ASP.NET front end for a c#/SQL server based call loggin system I have written. I have a webpage with a DataGrid dislaying various columns of data, and the last column is a view option. What I want to do is let the user click on the view (already using ButtonColumn for this), this then passes the value of the Reference Id in the data grid Row[0] to a new page where I can display the details for that call. So how do I pass a value from one page to another so I can execute an SQL query to get the rest of the info? Thanks in Advance Rich -- VFR ------------------------------------------------------------------------ Posted via http://www.codecomments.com ------------------------------------------------------------------------ Hi Rich,
You can pass the ID on the querystring when the user clicks the linkbutton. Here's how it looks in the grid page: <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"> <columns> <asp:templatecolumn> <itemtemplate> <asp:LinkButton runat="server" Text="Click Me" CommandArgument='<%# DataBinder.Eval(Container, "DataItem.ReferenceId") %>' CommandName="RefID" CausesValidation="false"> </asp:linkbutton> </itemtemplate> </asp:templatecolumn> <asp:boundcolumn DataField="stringvalue"></asp:boundcolumn> </columns> </asp:datagrid> Private Sub Page_Load _ (ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load DataGrid1.DataSource = CreateDataSource() DataGrid1.DataBind() End Sub Private Sub DataGrid1_ItemCommand _ (ByVal source As Object, ByVal e As _ System.Web.UI.WebControls.DataGridCommandEventArgs) _ Handles DataGrid1.ItemCommand If e.CommandName = "RefID" Then Response.Redirect("otherpage.aspx?ReferenceID=" & _ e.CommandArgument.ToString) End If End Sub Function CreateDataSource() As DataTable Dim dt As New DataTable Dim dr As DataRow dt.Columns.Add(New DataColumn _ ("ReferenceId", GetType(Int32))) dt.Columns.Add(New DataColumn _ ("StringValue", GetType(String))) dt.Columns.Add(New DataColumn _ ("CurrencyValue", GetType(Double))) dt.Columns.Add(New DataColumn _ ("Boolean", GetType(Boolean))) Dim i As Integer For i = 0 To 4 dr = dt.NewRow() dr(0) = i dr(1) = "Item " + i.ToString() dr(2) = 1.23 * (i + 1) dr(3) = (i = 4) dt.Rows.Add(dr) Next i Return dt End Function 'CreateDataSource And here's how you pick up the value in the SQL page, otherpage.aspx: Private Sub Page_Load _ (ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load If Not IsNothing(Request.QueryString("ReferenceID")) Then ' DO SQL stuff here Response.Write(Request.QueryString("ReferenceID").ToString) End If End Sub Does this help? Ken Microsoft MVP [ASP.NET] Toronto Show quoteHide quote "VFR" <VFR.1jw***@mail.codecomments.com> wrote in message news:VFR.1jwrts@mail.codecomments.com... > > Hi, > > I am a total ASP virgin and over the pst few nights have written a > ASP.NET front end for a c#/SQL server based call loggin system I have > written. > > I have a webpage with a DataGrid dislaying various columns of data, and > the last column is a view option. > > What I want to do is let the user click on the view (already using > ButtonColumn for this), this then passes the value of the Reference Id > in the data grid Row[0] to a new page where I can display the details > for that call. > > So how do I pass a value from one page to another so I can execute an > SQL query to get the rest of the info? > > Thanks in Advance > > Rich > > > > -- > VFR > ------------------------------------------------------------------------ > Posted via http://www.codecomments.com > ------------------------------------------------------------------------ > |
|||||||||||||||||||||||