How do I get the parameter for the delete command when I get the parameter for the select in another way?

I'm working with VS 2008.  I've got a data grid control, which I populate through a DropDownList that is data bound using a stored procedure.  When the DDL changes it updates the contents in the DataView control.  The DataView control is also data bound, and is populated using its own stored procedure and the code returned from the DDL once the user selects something.  I've got another stored procedure assigned to the DeleteCommand of the SqlDataSource, which I intend to use is with a delete CommnadField of the DataView control.  However, in this case I want to use the value from one of the fields in the selected row of the DataView as a parameter to the delete command (stored procedure), to delete the record from the relevant tables.  I don't want to use the ID that comes from the DDL; that is inappropriate (and just plain wrong).

So, how do I do what I want to do?  Walking through the wizard it doesn't give me a chance to set up the parameter for the Delete command; it only gives me a chance to setup the parameter for the select command.

 


Doctor Who
0
Doctor
12/23/2008 1:24:28 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
648 Views

Similar Articles

[PageSpeed] 23

So you have

a) DLL  bound to stored proc

b) DateView bound to stored proc that is dependent on DDL

You have a deletecommand for the dataview, you want to pass a param to the stored proc

I am guessing that you are using the sqldatasource, in this case you go to the delete tab, select your stored proc and when you are finishing you will need to define parameters...

Here you pick Control, and the control you want to look at, then click advanced properties and hook into that

I never use sqldatasouce and use n-layered apps, with objectdatasource or straight binding.

Best of luck

 


Joël Hébert [MVP ASP.NET]

Opulent ASP Development Inc.
www.opulentasp.com
Ottawa,Canada

Click "Mark as Answer" on the posts that helped you to help future readers to get the solutions
0
Joël
12/24/2008 2:48:05 PM

Yes, you've got a lot of it right, but not all.  It might be best if I include the relevant code so you'll have a better idea of what I'm talking about.  Here's the HTML for the 2 SDS's:

  

<asp:SqlDataSource ID="sdsLent" runat="server" 
	ConnectionString="<%$ ConnectionStrings:LibraryConnectionString %>" 
	SelectCommand="SELECT DISTINCT * FROM [Lent] ORDER BY [Lent To Name]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="sdssLentOut" runat="server" 
	ConnectionString="<%$ ConnectionStrings:LibraryConnectionString %>" 
	DeleteCommand="spRemoveLentRecord" DeleteCommandType="StoredProcedure" 
	SelectCommand="spsLentOutTo" SelectCommandType="StoredProcedure">
	<SelectParameters>
		<asp:ControlParameter ControlID="DropDownList1" Name="LentToID" 
			PropertyName="SelectedValue" Type="Int16" />
	</SelectParameters>
	<DeleteParameters>
		<asp:Parameter Name="Number" Type="Int16" />
	</DeleteParameters>
</asp:SqlDataSource>

 OK, now here's the code for the GridView:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
	BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" 
	CellPadding="3" DataKeyNames="Number" DataSourceID="sdssLentOut" 
	GridLines="Horizontal" onrowdeleting="GridView1_RowDeleting">
	<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
	<Columns>
		<asp:CommandField ShowDeleteButton="True" />
		<asp:BoundField DataField="Number" HeaderText="Number" 
			ReadOnly="True" SortExpression="Number" Visible="False" />
		<asp:BoundField DataField="Lent To ID" HeaderText="Lent To ID" 
			SortExpression="Lent To ID" Visible="False" />
		<asp:BoundField DataField="When Lent" DataFormatString="{0:MM/dd/yyyy}" 
			HeaderText="When Lent" SortExpression="When Lent" />
		<asp:BoundField DataField="Title" HeaderText="Title" 
			SortExpression="Title" />
		<asp:BoundField DataField="Lent To Name" HeaderText="Lent To Name" 
			SortExpression="Lent To Name" />
	</Columns>
	<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
	<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
	<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
	<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
	<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>

 

As you can see, the stored procedure to retrieve the data uses spsLentOutTo, whereas the SP to delete the data is spRemoveLentRecord.  Different data, different parameters, etc.  And the wizard seems bound and determined to only use the parameters for the SelectCommand with the DeleteCommand.  But that ain't right; I can't use that.  So, how do I specify the value from the column for the selected row of the GridView, when the user pressed that row's DeleteCommand button (CommandFIeld)?


Doctor Who
0
Doctor
12/25/2008 1:54:12 AM
Reply:

Similar Artilces:

how to get parameters from another form
Hi All, I have a checkbox in a form named form.And one submit button in one form named form1 and another submit button in another form form 2. Is there any value to access the check box name in one form to another form? Regards, Praveena 2007/9/3, Praveena Vittal <Praveena.Vittal@sun.com>: > Hi All, > > I have a checkbox in a form named form.And one submit button in one > form named form1 and another submit button in another form form 2. > > Is there any value to access the check box name in one form to another form? > You can't submit...

Can't get an INSERT command to work with form parameters
So I am using a SqlDataSource to insert a record into an Access DB.  I am using text boxes as the insert parameters.  The code is included below.  I can't figure it out, please help!<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Investor DatabaseConnectionString %>"            ProviderName="<%$ ConnectionStrings:Investor DatabaseConnectionString.ProviderName %>"         &nbs...

.net web service doesn't seem to get parameters from soap::lite
I'm using the method outlined in http://msdn.microsoft.com/en-us/library/ms995764.aspx, and also I have tried other methods on the web to call my vb.net (3.5) webservice. I can call any method that doesn't take parameters and that works fine. I can call my Authorize method which is used to authorize a credit card from a vb.net windows forms application. I can tell it isn't receiving any parameters because when I put the web service into debug, and set a break point I see all the parameters listed as nothing. This coding is really test coding I am using to verify proof of ...

Getting parameter from web address
I am trying to determine how to place the parameter that is on the website address and place onto my form to use.  If the address is www.testlink.com\Test.aspx?Test=yes   How do I get the "yes" from this to use on my form?  I am using VB as my language. Thanks!! Eddi Rae string somevariable = Request.Querystring["Test"];Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! EddiRae:I am trying to determine how to place the parameter that is on the website address and place onto my form to use.  If...

POST GET GET GET GET... WTH?
Hi, I'm at a loss to explain this... I have an ASPX page that I can't always navigate to. When I developed the app (it's Starter Kit Portal-based), I did it on my LAN and have had no trouble accessing the page. However, upon deployment, I see the following behavior: 1. POST request goes out looking for MyForm.aspx 2. GET request for MyForm.aspx 3. GET request for MyForm.aspx 4. ... X. GET request Sometimes, the page finally loads. Other times, it just ends up blank. Many times, it doesn't load at ALL the first POST - I just get a "The pa...

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

Get message that mozilla has to close. Get booted out of web site. Get message from Mozilla to report problem. Problem reporting will not work. Eventually I delete the report message.
Name: Linnea Hagberg Email: lhagbergatsmithcovedotcom Product: Mozilla Suite Summary: Get message that mozilla has to close. Get booted out of web site. Get message from Mozilla to report problem. Problem reporting will not work. Eventually I delete the report message. Comments: See above. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7 ...

How to use GridView row's Key selected for Delete as select parameter for another datasource
I'm not sure if the subject title makes sense, but it wasn't too easy to describe what I'm trying to do in one sentence! When a user clicks on the delete link in a GridView row, I want to run a stored proc, using the Key of the selected record as the parameter for the stored proc. I then want to programatically access the result of the stored proc (it'll be an integer value) for code-behind use. I wrote out a few steps to help me figure out what I need to do: 1) Get the value of PersonnelID (the DataKey) from the selected row in the GridView2) Set that Perso...

Get Selected Value for SqlDataSource Select Parameter located in Content Page from ListBox located in Master Page
i wanna Get Selected Value for SqlDataSource's Select Parameter located in Content Page from ListBox located in Master Page ? So how can i do that ?   Thanks in Advance..I am not a perfect programmer, but i have perfect programmers' habits [ i think so :)] Write a public property in the MasterPage that returns the ListBox text/value, so that you can call it in your contentpages. public partial class MasterPage1 : System.Web.UI.MasterPage{    public string ListBoxValue {        get { return ListBox1.SelectedItem.Value; } ...

Get parameter
Hello,I have the following url:http://localhost:2920/Account/Activate/f585f104-4d38-4d1d-972b-c177b7f64463?Key=0E0CEB5E671A256BAFF8C609CFB3D34FAccount is the controller, Activate the action, "f585f104-4d38-4d1d-972b-c177b7f64463" the id.How do I get the value of Key on my action code? The following is my current action code: public ActionResult Activate(Guid id) { ' ... return View(); }Thanks,Miguel     Request["Key"]   Just add it as a parameter to your action method, just like you did with id: public ActionResult Activate(G...

Delete parameter getting set to NULL why?
I have datagrid whose data source is set to SqlDataSource. SqlDataSource's connection string is set dynamically at pageload. When i click on delete link in gridview it executes delete command but row doesnt get deleted from data source. When i run Sql server profiler i found the delete statement is getting executed but the parameter is always null. why?   <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" Caption=&qu...

Getting parameters
Hi, I run my mozilla application with a shortcut like this: mozilla.exe -chrome chrome://myapp/content/ is it possible to get the arguments in the command line? For example if I run my application in this way: mozilla.exe -chrome chrome://myapp/content/ param1 param2 can I get "param1" and "param2" ? Thanks, Lithian. Lithian wrote: >I run my mozilla application with a shortcut like this: > >mozilla.exe -chrome chrome://myapp/content/ > >is it possible to get the arguments in the command line? For example if I run my application ...

How to get parameter in url ( by C# for .net)
  I would like to get parameter of ASP.NET script in URLexample : /localhost/example.asp?parameter1How can i to get this parameter ? can you give me a example? ( using C#) Thanks a lot   JC To get a querystring you can use the Request.Querystring property: Request.Querystring("parameter1")/Fredrik Normén - fredrikn @ twitterMicrosoft MVP, MCSD, MCAD, MCTASPInsidersMy Blog Actually in C# it would be://this takes request parameters only from the query string Request.QueryString["parameter1"]; //this one works for bot - form and query string Request["paramet...

Help! Getting values from SqlDataSource command parameters
 I'm trying to get the value from a sql command in a sqldatasource and assign it to a session variable for use on another form.  Here is the SQL insert command I'm using: BEGIN TRANSACTION; INSERT INTO DEV.ENTITY (CompanyName, FirstName, MiddleName, LastName, EntityType) VALUES (@CompanyName, @FirstName, @MiddleName, @LastName, 'Owner'); SET @nextEntityId=(SELECT MAX(EntityId) FROM DEV.ENTITY); COMMIT; Here is the code for the SqlDataSource called EntityDataSource: <asp:SqlDataSource ID="EntityDataSource" runat="server"  &n...

Web resources about - How do I get the parameter for the delete command when I get the parameter for the select in another way? - asp.net.web-forms

Parameter - Wikipedia, the free encyclopedia
A parameter (from the Ancient Greek παρά , "para", meaning "beside, subsidiary" and μέτρον , "metron", meaning "measure"), in its common meaning, ...

fb_source Parameter - Facebook-Entwickler
This document lists the complete list of values for the fb_source parameter that is returned with th...

Google / Firefox Parameter - Flickr - Photo Sharing!
HS what? www.seroundtable.com/archives/017105.html

Cat 8: TIA performance standards committee chairman previews parameters of forthcoming twisted-pair cable ...
Category 8, the next-generation twisted-pair cabling specification, is still in development, but the outlook looks quite positive that it will ...

Philippine president asks for 'parameters' of Mayon Volcano tours
Philippine president asks for 'parameters' of Mayon Volcano tours People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, Apr, May, ...

Alternatives to boolean parameters
... ) { PrintLine ( item . Name ); if ( printDetails ) { PrintLine ( item . Description ); } } } Aha! Now can see that the boolean parameter ...

Exporting Error (Error in Parameter...: Apple Support Communities
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability ...

Apple tech monitors device aging, adjusts operating parameters to ensure optimal performance
... describing a method of monitoring the aging of a device's electronics, comparing the data with a global average and modifying operating parameters ...

Is it poor programming practice to pass parameters as objects?
... a free, community-powered network of 100+ Q&A sites . Risser asked: So, we've got a guy who likes to write methods that take Objects as parameters, ...

Parameter Short Film Competition sponsored by Grolsch
Grolsch presents Parameter The A.V. Club Short Film Competition Please Enter Your Date of Birth Ineligible entry Enter For people over the age ...

Resources last updated: 1/7/2016 4:11:55 PM