.NET Forum / ASP.NET / Web Controls / May 2005
Please...Expert needed.
|
|
Thread rating:  |
Tim Farrell - 23 May 2005 20:13 GMT I have a webform that uses a linkbutton control for the purposes of obtaining a detailed view of the record.
<asp:LinkButton Runat="server" ID="detail" CommandName="get_detail" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID")%>'> <%# DataBinder.Eval(Container.DataItem, "Cust_Name")%> </asp:LinkButton></td>
The code behind: private void Repeater1_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { int ItemID = Convert.ToInt32(e.CommandArgument); }
public void get_detail(object sender, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { if (e.CommandName == "get_detail") { Panel1.Visible = false; Panel2.Visible = true; Select_Full.Fill(full1); Select_Comments.Fill(com1); DataBind(); } }
If I put a breakpoint in my build on public statement and mouseover the e.CommandArgument above I can see the integer value of the selected record from teh webform.
The problem is, the SQL stored procedure cannot and thus complains that it is looking for a value for @ItemID that does not exist.
Can some please tell me how to fix this so I can pass the selected value along to my SP?
Thank you very much.
Tim
Brock Allen - 23 May 2005 21:50 GMT > The problem is, the SQL stored procedure cannot and thus complains > that it is looking for a value for @ItemID that does not exist. You need to post the code that calls into the StoredProc.
-Brock DevelopMentor http://staff.develop.com/ballen
Tim Farrell - 24 May 2005 11:56 GMT Brock,
Here is the code that calls for the use of the Stored Procedure(Web Form Designer Generated Code):
this.sqlSelectCommand2.CommandText = "[Select_Full]"; this.sqlSelectCommand2.CommandType = System.Data.CommandType.StoredProcedure; this.sqlSelectCommand2.Connection = this.sqlConnection1; this.sqlSelectCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null)); this.sqlSelectCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ItemID", System.Data.SqlDbType.Int, 4, "ItemID"));
Here is the SP:
ALTER PROCEDURE dbo.Select_Full ( @ItemID int ) AS SET NOCOUNT ON; SELECT ItemID, Rec_Date, Cust_Name, Client_Number, Region, Disp, Contact_Date, Sales_Rep, Reason, Sale_Affect, Service_Affect, Lisc_key, Strobe_Rel, iStrobe_Rel, Feat_Affect, CT_Number, PT_Number, Short_Desc FROM HSCTI WHERE (ItemID = @ItemID)
Thank you for your time (and patience).
Tim
Craig - 24 May 2005 14:11 GMT Hi Tim.
Will you post the code where you actually make your database call? You've posted your variable declarations but no code showing where you've executed any database calls or populated any stored procedure parameters.
Craig Hunt, MCSE, MCDBA
> Brock, > [quoted text clipped - 30 lines] > > Tim Tim Farrell - 24 May 2005 14:23 GMT Craig,
I guess that is what has me confused. I built this page directly from the wizards. I setup 3 sqlDataAdapters and 3 Datasets. Placed my Summary Datagrid inside the first panel, then my two datalists in the second. The Summary Datagrid comes up fine, but when I click on the linkbutton, I get the error specified earlier.
I guess my confusion comes from the fact that I thought the database connection etc was called from the fill function. I thought the db stuff that included in the last post was sufficient for this purpose.
Knowing that there is a piece missing here, do you know of any documentation that can inform me as to what and where I need to add the SQL code you make reference to?
And while I eagerly await your response, I will throw my head into a wall. ;)
Sorry for the long winded response, but I thought you should know where I coming from. Obviously a newbie in this arena.
Thanks Craig.
Sincerely,
Tim
Tim Farrell - 24 May 2005 16:50 GMT Ok, I think I'm getting closer but different error. What I did was add a parameter to push to the SP like so:
public void get_detail(object sender, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { this.sqlSelectCommand2.Parameters.Add( new SqlParameter("@ItemID", e.CommandArgument)); if (e.CommandName == "get_detail") { Panel1.Visible = false; Panel2.Visible = true;
Select_Full.Fill(full1); Select_Comments.Fill(com1); DataBind(); } }
The error message indicates: The procedure or function Select_Full has too many arguments.
Here is the function: this.Select_Full.SelectCommand = this.sqlSelectCommand2; this.Select_Full.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { new System.Data.Common.DataTableMapping("Table", "HSCTI", new System.Data.Common.DataColumnMapping[] { new System.Data.Common.DataColumnMapping("ItemID", "ItemID"), new System.Data.Common.DataColumnMapping("Rec_Date", "Rec_Date"), new System.Data.Common.DataColumnMapping("Cust_Name", "Cust_Name"), new System.Data.Common.DataColumnMapping("Client_Number", "Client_Number"), new System.Data.Common.DataColumnMapping("Region", "Region"), new System.Data.Common.DataColumnMapping("Disp", "Disp"), new System.Data.Common.DataColumnMapping("Contact_Date", "Contact_Date"), new System.Data.Common.DataColumnMapping("Sales_Rep", "Sales_Rep"), new System.Data.Common.DataColumnMapping("Reason", "Reason"), new System.Data.Common.DataColumnMapping("Sale_Affect", "Sale_Affect"), new System.Data.Common.DataColumnMapping("Service_Affect", "Service_Affect") , new System.Data.Common.DataColumnMapping("Lisc_key", "Lisc_key"), new System.Data.Common.DataColumnMapping("Strobe_Rel", "Strobe_Rel"), new System.Data.Common.DataColumnMapping("iStrobe_Rel", "iStrobe_Rel"), new System.Data.Common.DataColumnMapping("Feat_Affect", "Feat_Affect"), new System.Data.Common.DataColumnMapping("CT_Number", "CT_Number"), new System.Data.Common.DataColumnMapping("PT_Number", "PT_Number"), new System.Data.Common.DataColumnMapping("Short_Desc", "Short_Desc")})}); // // sqlSelectCommand2 // this.sqlSelectCommand2.CommandText = "[Select_Full]"; this.sqlSelectCommand2.CommandType = System.Data.CommandType.StoredProcedure; this.sqlSelectCommand2.Connection = this.sqlConnection1; this.sqlSelectCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@RETURN_VALUE", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.ReturnValue, false, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null)); this.sqlSelectCommand2.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ItemID", System.Data.SqlDbType.Int, 4, "ItemID")); // // full1 // this.full1.DataSetName = "Full"; this.full1.Locale = new System.Globalization.CultureInfo("en-US");
This was code generated by the GUI in the Web Form Designer generated code.
Also, If there is a better way to obtain this functionality instead of using the GUI generated code I'm all for suggestions.
Sincerely,
Tim
Brock Allen - 26 May 2005 16:52 GMT > Also, > If there is a better way to obtain this functionality instead of using > the > GUI generated code I'm all for suggestions. I'd suggest ditching the drag and drop. I always write my DB access code manually. It's not that much work and you have so much more control over and clarity in your code. Here's a sample snippet:
using (SqlConnection cn = new SqlConnection("server=localhost;database=pubs;trusted_connection=yes;")) { using (SqlCommand cmd = cn.CreateCommand()) { cmd.CommandText = "YourProcName"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Item", YourValueHere); cn.Open(); using (SqlDataReader rdr = cmd.ExecuteReader()) { // data bind to rdr in here } } }
Of course, you'd want to pull the connection string from the web,config, but you get the idea how simple it is to write the DB code manually.
-Brock DevelopMentor http://staff.develop.com/ballen
Tim Farrell - 27 May 2005 13:03 GMT Brock,
In you code here:
cmd.Parameters.Add("@Item", YourValueHere);
How would you script the value above if teh value is coming from a linkbutton control.
If my linkbutton control code is such:
<asp:LinkButton Runat="server" ID="detail" CommandName="get_detail" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID")%>'> <%# DataBinder.Eval(Container.DataItem, "Cust_Name")%></asp:LinkButton>
Would you code it like this? cmd.Parameters.Add("@Item", @detail);
How would you pull the value from the linkbutton control?
Thank you for ally our help.
Tim
Brock Allen - 30 May 2005 19:54 GMT Well, just access the LinkButton object and get its CommandArgument property. I suspect you're having problems getting the LinkButton. You can do this by handling the DataGrid's (I assume it's in a DataGrid) ItemCommand event. The DataGridCommandEventArgs.Item is the row in the DataGrid that fires the event. So you can use e.Item.FindControl("detail") to get a reference to the LinkButton. Once you have that, then you can get its properties.
-Brock DevelopMentor http://staff.develop.com/ballen
> Brock, > [quoted text clipped - 19 lines] > > Tim Tim Farrell - 31 May 2005 13:56 GMT Brock,
I think you just found my problem(or at least what I think is one of them). You indicated that you assumed that I was using a datagrid when in fact I am not. I was attempting to use the Repeater due to its flexibility in presentation. I can't format the data the way I would like to using the datagrid.
Is the datagrid the only control I can use to facilitate this functionality?
Is there a way to wire the Repeater so I can display both a summary of the data and a detail view of the table coming from the same table?
Thanks for all you help.
Tim
Brock Allen - 31 May 2005 15:54 GMT The Repeater also has an ItemCommand event, so everything from my last post applies.
-Brock DevelopMentor http://staff.develop.com/ballen
> Brock, > [quoted text clipped - 13 lines] > > Tim
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|