Hi Sck10,
Welcome to the ASPNET newsgroup.
From your description, I understand in your ASP.NET page, there has a
Gridview and a FormView control on it. The FormView control will display
the detailed data depend on a certain key value. This key value could be
from the GridView's SelectedValue or from the querystirng, so you're
wondering a proper approach to make it use querystring value first, if not
exist, turn to use the GridView's selectedvalue, correct? If anything I
missed, please feel free to let me know.
Based on my understanding, for such scenario, it's hard to use single
datasource to perform the queyr because each datasource control can only
specify a single type of parameter source. I think you can consider put two
datasource controls on the page, one select the query depend on a
controlparameter source(from Gridview), another depend on querystring
parameter. Then, in the page_load event, we can check whether the
querystirng contains the keyvalue, if exists, associate the Formview with
the Querystring sourced datasource control, otherwise, use the GridView
sourced datasource control. For example:
===========================
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NewLocalNorthWind %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
[Categories]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$
ConnectionStrings:NewLocalNorthWind %>"
SelectCommand="SELECT [CategoryID], [CategoryName],
[Description] FROM [Categories] WHERE ([CategoryID] = @CategoryID)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1"
Name="CategoryID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
===========================
============================
protected void Page_Load(object sender, EventArgs e)
{
string strCid = Request.QueryString["cid"];
if (!string.IsNullOrEmpty(strCid))
{
try
{
FormView1.DataSourceID = "SqlDataSource3";
return;
}
catch (Exception ex)
{
//do nothing
}
}
FormView1.DataSourceID = "SqlDataSource2";
}
============================
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)