Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2008, 04:12 AM
Registered User
 
Join Date: Oct 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Can not Edit gridview having TemplateField

 Hi,

I have a gridview which is having a TemplateField with a checkbox.When I edit this field an erro is occured saying,"Could not find control 'chkPrimary' in ControlParameter 'Primary_Skill'."I am giving the code below..Plz help me...

  <asp:GridView id="gdSkills" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="Emp_code,Skill_Id" PageSize="15" AllowPaging="True" AutoGenerateColumns="False">
        <HeaderStyle CssClass="gridViewHeader" />
        <RowStyle CssClass="gridViewRowStyle" Wrap="False" Width="100%" />
        <AlternatingRowStyle CssClass="gridViewAlternative" Wrap="False" Width="100%" />
                 <Columns>
                  <asp:BoundField DataField="Skill_name" HeaderText="Skill" ReadOnly="True" />
                  <asp:BoundField DataField="No_Months" HeaderText="No of Months" />
                   <asp:TemplateField HeaderText="Primary">
                     <ItemTemplate>
                         <asp:CheckBox ID="chkPrimary" runat="server" Checked='<%# GetBoolean(Eval("Skill_Id"),Eval("Emp_code"))%>' />
                      </ItemTemplate>
                   </asp:TemplateField>
                   <asp:CommandField ShowEditButton= "True"/>
                   </Columns>
         </asp:GridView>
         <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ProviderName="System.Data.SqlClient"

                ConnectionString="<%$ ConnectionStrings:MyDatabase%>"


                SelectCommand="select ES.Skill_id,Skill_name,emp_code,No_Months,Primary_ Skill from Skill S
                               join Emp_skills ES on S.Skill_id=ES.Skill_id
                               where emp_code=@Emp_code order by Skill_name"
                UpdateCommand="update emp_Skills set No_Months=@No_Months,Primary_Skill=@Primary_Skill where Skill_id=@Skill_id AND EMP_CODE=@Emp_Code">
                  <SelectParameters>
                   <asp:SessionParameter Name="Emp_code" SessionField="Empcode" Type="String" />
                  </SelectParameters>
                  <UpdateParameters>
                      <asp:Parameter Name="No_Months" Type="Double" />
                      <asp:Parameter Name="Skill_id" Type="Int32" />
                      <asp:ControlParameter Name="Primary_Skill" ControlID="chkPrimary" />
                      <asp:SessionParameter Name="Emp_code" SessionField="Empcode" Type="String" />
                  </UpdateParameters>
         </asp:SqlDataSource>


 
Old March 5th, 2008, 05:33 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Inside you <asp:TemplateField> you have an <ItemTemplate>. To make the template field editable I'd assume you'd also need a <EditItemTemplate>.

http://msdn2.microsoft.com/en-us/lib...mtemplate.aspx

/- Sam Judson : Wrox Technical Editor -/
 
Old March 5th, 2008, 04:42 PM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'd think that it is not possible for SqlDataSource control to know the existence of chkPrimary control inside the GridView in this case. I mean there could be n+1 rows inside that GridView. Which CheckBox is the right one?

I would think the only way to solve this is to change that parameter a bit:

<asp:Parameter Name="Primary_Skill" Type="Boolean" />

And add Selecting event handler to SqlDataSource where you set the value for Primary_Skill parameter:

Code:
protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
    e.Command.Parameters["Primary_Skill"].Value = ((CheckBox)gdSkills.Rows[...].Cells[3].Controls[1]).Checked;
}
Or I could be totally mistaken of course. Wouldn't be the first time :)
 
Old March 5th, 2008, 06:11 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Yet again a simple google search provides multiple possible solutions:
http://geekswithblogs.net/azamsharp/.../27/89475.aspx

Please, always try a search google first beore posting.

/- Sam Judson : Wrox Technical Editor -/
 
Old March 6th, 2008, 06:36 AM
Authorized User
 
Join Date: Sep 2007
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Coolcoder2007 is talking about GridView. So the problem still persist that which row has the correct CheckBox.





Similar Threads
Thread Thread Starter Forum Replies Last Post
[Resolved] GridView TemplateField - get value snufse ASP.NET 2.0 Basics 25 July 29th, 2008 07:25 AM
GridView edit problem mike72 ASP.NET 2.0 Basics 8 January 3rd, 2007 07:59 PM
edit item in gridview al-hijjawi Visual Studio 2005 0 December 27th, 2006 03:20 PM
edit gridview anurag_ur ASP.NET 2.0 Basics 3 June 21st, 2006 03:21 AM
edit gridview anurag_ur ASP.NET 2.0 Basics 0 June 20th, 2006 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.