FormView datasource (asp.net 2.0)

S

sck10

Hello,

I have a GridView that has AutoGenerateSelectButton="true". When the
"Select" link is clicked, it opens a FormView with the appropriate data.
Below is the following SelectParameter that is used to populate the
FormView.

"gvSearchList" is the ID for the GridView.

<SelectParameters>
<asp:ControlParameter ControlID="gvSearchList"
DefaultValue="NoParameter" Name="LabModificationID"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>

I have two situations in which I want to open the form. With or without a
querystring. If I don't have a query string value, I want it to function as
it currently does. My question is how can I bypass using to GridView to
send the querystring as the parameter value?
 
S

Steven Cheng[MSFT]

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top