473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

FormView datasource (asp.net 2.0)

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?
--
Thanks in advance,

sck10
Mar 29 '06 #1
1 3730
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.)




Mar 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sck10 | last post by:
Hello, I just started learning about the formview control in asp.net 2.0. I am using the following. The problem I am having is that the data is not showing on the web. <form id="form1"...
3
by: sck10 | last post by:
Hello, I am creating a form for users to enter information about a lab and the members of the lab. I have one form (FormView) that they use to enter information about that lab. The keyvalue is...
2
by: P. Yanzick | last post by:
Hello, I am creating an edit template for a FormView control, changing one of the textboxes to a dropdown box. The dropdown will be populated from a simple table with the primary key, and a...
3
by: Jurgen Appelo | last post by:
I asked this question earlier, but unfortunately the two replies I got did not solve the problem. Here it is again, but now with the code: After an Update my FormView always loses its viewstate...
3
by: Bas Paap | last post by:
I'm having a problem with formviews and DropDownLists in ASP.NET 2.0. I'm using a formview to insert an order into a database. Part of the order is the customer. Currently, I have a dropdownlist...
2
by: Kelly | last post by:
I'm fairly new to ASP.NET2, but I have an ASP 3.0 background, and I've been experimenting with the DataSource and FormView widgets. I wound up having some questions along the way which I hope you...
1
by: Cliff | last post by:
Hi, I expect with this code to see the FormView in the browser but nothing appears (no error, no formview). I checked with variable 'x' and i know there is one record in the dataset. The...
1
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is...
0
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.