Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
My update command is not working. I have pass 3 parameters. 2 parameter is dropdownvalue and one is bound fields. How to pass dropdown values in update parameter?
My code is below
<asp:GridView ID="grdDeptEmp" runat="server" AutoGenerateColumns="False"
                       DataKeyNames="emp_number" Cssclass="tabulardata" DataSourceID="dsOtherDept1"
                   class="tabulardata" width="100%" HorizontalAlign="Center"  OnRowCancelingEdit="grdDeptEmp_RowCancelingEdit"
                   OnRowDataBound="grdDeptEmp_RowDataBound" OnRowEditing="grdDeptEmp_RowEditing" OnRowUpdating="grdDeptEmp_RowUpdating"
                   OnRowCommand="grdDeptEmp_RowCommand" ShowFooter="True"
                       OnRowDeleting="grdDeptEmp_RowDeleting" AllowPaging="True">
                             <columns>
                               <asp:TemplateField HeaderText="Sl.No" ItemStyle-HorizontalAlign="Center"
                                        ItemStyle-Width="2%">
                                        <itemtemplate>
                                            <asp:Label ID="Sno" runat="server">
                                        </itemtemplate>
                                        <itemstyle horizontalalign="Center" />

                               <asp:TemplateField HeaderText="EmpNumber"  HeaderStyle-HorizontalAlign="Left">
                                   <edititemtemplate>
                                       <asp:Label ID="lblEmpNo" runat="server" Text='<%# Bind("emp_number") %>'>
                                   </edititemtemplate>
                                   <itemtemplate>
                                       <asp:Label ID="lblEmpNo" runat="server" Text='<%# Bind("emp_number") %>'>
                                   </itemtemplate>
                                   <HeaderStyle HorizontalAlign="Left" />

                               <%-- <asp:BoundField HeaderText="Emp_Number" Visible="true" DataField="emp_number"
                                        ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="emp_number">
                                        <itemstyle horizontalalign="Center" width="5%" />
                                --%>
                               <asp:BoundField HeaderText="Name" DataField="name"
                                        ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="name">
                                        <itemstyle horizontalalign="Center" width="17%" />

                                <asp:BoundField HeaderText="Designation" DataField="emp_designation"
                                        ItemStyle-HorizontalAlign="center" ReadOnly="true" SortExpression="emp_designation">
                                        <itemstyle horizontalalign="Center" width="17%" />

                                <asp:TemplateField HeaderText="From Period" HeaderStyle-HorizontalAlign="Left">
                                   <edititemtemplate>
                                       <asp:DropDownList ID="cmbFrm" runat="server" Style="width: 150px;"
                                           DataSourceID="dsOtherDept1" DataTextField="FromPeriod" DataValueField="FromPeriod"
                                           AppendDataBoundItems="true">
                                           <asp:ListItem Text="Please Select" Value="">

                                   </edititemtemplate>
                                   <itemtemplate>
                                       <asp:Label ID="lblFrm" runat="server" Text='<%# Eval("FromPeriod") %>'>
                                   </itemtemplate>
                                    <HeaderStyle HorizontalAlign="Left" />

                                <asp:TemplateField HeaderText="To Period" HeaderStyle-HorizontalAlign="Left">
                                   <edititemtemplate>
                                       <asp:DropDownList ID="cmbTo" runat="server" Style="width: 150px;"
                                           DataSourceID="dsOtherDept1" DataTextField="ToPeriod" DataValueField="ToPeriod"
                                           AppendDataBoundItems="true">
                                           <asp:ListItem Text="Please Select" Value="">

                                   </edititemtemplate>
                                   <itemtemplate>
                                       <asp:Label ID="lblTo" runat="server" Text='<%# Eval("ToPeriod") %>'>
                                   </itemtemplate>
                                    <HeaderStyle HorizontalAlign="Left" />

                               <asp:TemplateField HeaderText="Edit" ShowHeader="False" HeaderStyle-HorizontalAlign="Left">
                                   <edititemtemplate>
                                       <asp:LinkButton ID="lbkUpdate" runat="server" CausesValidation="True" CommandName="Update" Text="Update">
                                       <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel">
                                   </edititemtemplate>
                                   <itemtemplate>
                                       <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit">
                                   </itemtemplate>
                                   <HeaderStyle HorizontalAlign="Left" />

                               <asp:CommandField HeaderText="Delete" ShowDeleteButton="True" ShowHeader="True" />
                           </columns>

                   <asp:SqlDataSource ID="dsOtherDept1" runat="server"
                           ConnectionString="<%$ConnectionStrings:MPP%>"
                           SelectCommand="Select distinct V.emp_number as emp_number,emp_name+' '+emp_initial as name,emp_designation,Manpower_Division_ID,FromPeriod, ToPeriod from idpeapp.dbo.view_employee V inner join OtherDeptEmp O on V.emp_number = O.emp_number order by name"
                           UpdateCommand="update OtherDeptEmp set FromPeriod=@FromPeriod,ToPeriod=@ToPeriod where emp_number=@emp_number">
                           <updateparameters>
                                 <asp:Parameter Name="FromPeriod" Size="20" Type="String" />
                                 <asp:Parameter Name="ToPeriod" Size="20" Type="String" />
                                 <asp:Parameter Name="emp_number" Type="Int32" />
                            </updateparameters>
Posted
Updated 12-Jul-11 0:49am
v3
Comments
Christian Graus 11-Jul-11 22:07pm    
Your best bet is to ditch this drivel and write professional quality code, where your data layer is separate to your presentation layer.
gani7787 12-Jul-11 0:17am    
Hi,

Can anyone tell me what is the problem in update command not working when i pass dropdown values.
Uday P.Singh 17-Jul-11 8:07am    
I agree with Christian, if you write code like this, you will always find yourself in these kinds of problems, and it would be difficult to debug as well.

1 solution

 
Share this answer
 
Comments
Tarun.K.S 17-Jul-11 7:58am    
Yep that must be the reason. 5+
Espen Harlinn 17-Jul-11 11:19am    
Nice work, my 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900