I have two web pages- the first is a GridView and the second is a FormView. I have been able to retrieve the DataKey value from the GridView and pass it to the FormView page. Now I need to use that key value for my selection query. How do I assign that value? Code example would help in C#.
This is my page_load code:
protected void Page_Load(object sender, EventArgs e)
{
string CompanyStr = Server.HtmlEncode(Request.QueryString["param1"]);
string ClientKey = Request.QueryString["param2"];
Label lbl = FormView1.FindControl("CompanyID") as Label;
lbl.Text = CompanyStr;
}
And this is the FormView code:
<asp:FormView ID="FormView1" runat="server" DefaultMode="Insert" DataKeyNames="ClientKey"
DataSourceID="SqlDataSource1" onitemcommand="onItemCommand">
The ClientKey is the variable that needs to be set.
It sounds like you want to use a Select Parameter in your
SQLDataSource1markup (the one referenced in yourFormViewdeclaration) to do this. This should work:Notice the
WHEREclause in theSelectCommandproperty. I don’t know what the rest of your query looks like, but having that on the end should filter yourFormViewdown to what you want.This should automatically pull the value from your query string, and your FormView will have the proper record loaded.