|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Please...Expert needed.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 > The problem is, the SQL stored procedure cannot and thus complains You need to post the code that calls into the StoredProc.> that it is looking for a value for @ItemID that does not exist. -Brock DevelopMentor http://staff.develop.com/ballen 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 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 Show quoteHide quote "Tim Farrell via DotNetMonster.com" <fo***@DotNetMonster.com> wrote in message news:ad1fa8c8e0704123945726337154acda@DotNetMonster.com... > 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 > > -- > Message posted via http://www.dotnetmonster.com 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 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 -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-web-controls/200505/1 > Also, I'd suggest ditching the drag and drop. I always write my DB access code > If there is a better way to obtain this functionality instead of using > the > GUI generated code I'm all for suggestions. 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 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 -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-web-controls/200505/1 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 Show quoteHide quote > 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,
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 -- Message posted via DotNetMonster.com http://www.dotnetmonster.com/Uwe/Forums.aspx/asp-net-web-controls/200505/1 The Repeater also has an ItemCommand event, so everything from my last post
applies. -Brock DevelopMentor http://staff.develop.com/ballen Show quoteHide quote > 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 >
Click checkbox's label - javascript onclick gets called twice
Problem with FindControl Changing the document.title from a user control Validation not working in paging Using a Stylesheet in a User Control The nowrap Property of TD Tags Text control - password Handling Events for Dynamically Created Controls Positioning Panel on WebForm at runtime File uploaded to server....How can I delete it? |
|||||||||||||||||||||||