Click here to Skip to main content
14,879,563 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all ,
i have the follwing grid i am trying to edit and insert in the grid
i have some problems
first :
when i click on the edit link button it does not work at the first time you need to click again and it works fine.
second :
in bindgrid in editmode the row databound could not find dropdownlist this is because the name of dropdownlist in edit mode not the same in itemtemplate and i can not make them the same it will cause an error as repeated control so how can i bind the grid in edit mode and also in the insert mode ?
third :
i have a stored procedure used to edit and insert in same sp it is inserting or updating in two tables : master and details. After insert or update in the master table, the same action should occur in details table. So i should get the scop_identity () but the problem in sql server 2008 scope_identity() is, that it always returns null so an insertion or updation in master will not happen
i just tried to find as to why this problem occurred and i found that an error occurred in the setup of sql server 2008 which caused this problem
how can i fix this problem? i don't know ?
i tried to make auto increment column in the master table and get the max value this works in insert but does not work in update
could any one help me please ?
this is my code :
gridview :
ASP.NET
<asp:GridView ID="GridView1" runat="server" ShowFooter ="True"
         AutoGenerateColumns="False" onrowdatabound="GridView1_RowDataBound"
         onrowcancelingedit="GridView1_RowCancelingEdit"
         onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
         onrowupdating="GridView1_RowUpdating">
     <Columns>
         <asp:TemplateField>
     <ItemTemplate>
     <asp:LinkButton  ID ="lbllinkbtn"  runat ="server" CausesValidation ="false" CommandName="EDit"  Text="EDIT">
     </asp:LinkButton>
     <asp:LinkButton ID ="lbldeletebtn" runat="server" CommandName="Delete" Text ="Delete">
     </asp:LinkButton>

     </ItemTemplate>
     <EditItemTemplate>
     <asp:LinkButton ID="lblupdatebtn" runat ="server" CommandName ="Update"  CausesValidation="false" Text ="Update">
     </asp:LinkButton>
     <asp:LinkButton ID="lblcancelbtn" runat="server" CommandName="Cancel"  Text="Cancel" CausesValidation="false">
     </asp:LinkButton>

     </EditItemTemplate>
     <FooterTemplate>
     <asp:LinkButton ID="lblinsertbtn" Text="Insert"  runat ="server" CausesValidation="false" CommandName="Insert" OnClick="insert_row">
     </asp:LinkButton>
     <asp:LinkButton ID="lblcancel" runat ="server" Text ="Cancel" CommandName ="Cancel"  CausesValidation ="false">
     </asp:LinkButton>
     </FooterTemplate>


     </asp:TemplateField>
         <asp:TemplateField HeaderText="Transaction Number">

                              <ItemTemplate>
                                 <asp:Label ID="lbltransaction_num" runat="server"
                                     Text='<%#Bind("transaction_num")%>'></asp:Label>
                             </ItemTemplate>
                             <EditItemTemplate>
                                 <asp:Label ID="lbltrans_num" runat="server"
                                     Text='<%#Bind("transaction_num")%>'></asp:Label>
                             </EditItemTemplate>
                        <%--  <FooterTemplate>
                             <asp:Label ID="LBLNUM" runat ="server" >
                             </asp:Label>
                             </FooterTemplate>--%>


                         </asp:TemplateField>
         <asp:TemplateField HeaderText="Transaction Type ">

                              <EditItemTemplate>
                                  <asp:DropDownList ID="ddlTrans_type" runat="server" Width ="100" OnSelectedIndexChanged="choose_service_code" AutoPostBack ="true" EnableViewState="true" ></asp:DropDownList>
                              </EditItemTemplate>


                              <ItemTemplate>

                                 <asp:DropDownList  ID="ddlTrans_type" runat="server" Width ="100"  ></asp:DropDownList>
                             </ItemTemplate>
                            <FooterTemplate>
                             <asp:DropDownList ID="ddlTrans_type" runat="server" Width ="100" ></asp:DropDownList>

                            </FooterTemplate>
                         </asp:TemplateField>
         <asp:TemplateField HeaderText="Transaction Date">
                             <EditItemTemplate>
                                 <asp:TextBox ID="TXTDATE" runat="server"
                                     Text='<%# Bind("transaction_date") %>'></asp:TextBox>
                             </EditItemTemplate>
                             <ItemTemplate>
                                 <asp:Label ID="Label1" runat="server" Text='<%# Bind("transaction_date") %>'></asp:Label>

                             </ItemTemplate>
                             <FooterTemplate>
                             <asp:TextBox ID ="txttransaction_date" runat ="server" >
                             </asp:TextBox>


                             </FooterTemplate>
                         </asp:TemplateField>
         <asp:TemplateField HeaderText="Customer Number ">

                           <EditItemTemplate>
                                 <asp:DropDownList ID="edit_ddlcustomer" runat="server" Width ="100"  > </asp:DropDownList>
                             </EditItemTemplate>

                            <ItemTemplate>
                                 <asp:DropDownList ID="item_ddlcustomer" runat="server" Width ="100"> </asp:DropDownList>
                             </ItemTemplate>
                            <FooterTemplate>
                             <asp:DropDownList ID="footer_ddlcustomer" runat ="server" Width ="100">
                             </asp:DropDownList>
                             </FooterTemplate>
                         </asp:TemplateField>
         <asp:TemplateField HeaderText="Service Code">
                             <EditItemTemplate>
                                 <asp:DropDownList ID="edit_service" runat="server"></asp:DropDownList>
                             </EditItemTemplate>
                             <ItemTemplate>
                                 <asp:DropDownList ID="item_service" runat="server" Width="100"></asp:DropDownList >
                             </ItemTemplate>
                           <%--  <FooterTemplate>
                             <asp:Label ID="footer_service" runat ="server" >
                             </asp:Label>

                             </FooterTemplate>--%>
                         </asp:TemplateField>
                       <asp:TemplateField HeaderText="Quantity">
                             <EditItemTemplate>
                                 <asp:TextBox ID="txtedit_qty" runat="server" Text='<%# Bind("qty") %>'></asp:TextBox>
                             </EditItemTemplate>
                             <ItemTemplate>
                                 <asp:Label ID="lbl_qty" runat="server" Text='<%# Bind("qty") %>'></asp:Label>
                             </ItemTemplate>

                             <FooterTemplate>
                             <asp:TextBox ID="txtfooter_qty" runat="server">
                             </asp:TextBox>

                             </FooterTemplate>
                      </asp:TemplateField>


     </Columns>
     </asp:GridView>




codebehind:


ASP
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              DropDownList ddlTrans_type = e.Row.FindControl("ddlTrans_type") as DropDownList;
              ddlTrans_type.DataSource = h.get_transaction_type();

              ddlTrans_type.DataTextField = "transaction_type";
              ddlTrans_type.DataValueField = "transaction_type";
              ddlTrans_type.DataBind();
              DropDownList item_ddlcustomer = e.Row.FindControl("item_ddlcustomer") as DropDownList;
              item_ddlcustomer.DataSource = h.get_customer_bal();
              item_ddlcustomer.DataTextField = "customer_name";
              item_ddlcustomer.DataValueField = "customer_num";
              item_ddlcustomer.DataBind();
              DropDownList item_service = e.Row.FindControl("item_service") as DropDownList;
              item_service.DataSource = h.get_service_data_grid();
              item_service.DataTextField = "service_code";
              item_service.DataValueField = "service_code";
              item_service.DataBind();




          }

      }



SQL
update tbl_transaction
				set transaction_type=@transaction_type,
				customer_num=@custom_number,
				transaction_date=@trans_date
				where transaction_num=@transaction_num ;
				--fix 
				select @fix_scope_prob=transaction_num   from tbl_transaction where transaction_num=@transaction_num ;
				
				--select @fix_scope_prob=transaction_num   from tbl_transaction where fix_scope_identity_pr=(select MAX(fix_scope_identity_pr) from tbl_transaction)  ;
				
				update tbl_transaction_service
				set qty=@qt
				where transaction_num=@fix_scope_prob and service_code=@servicecode ;
				
				select @return_val=@fix_scope_prob ;
Posted
Updated 13-Apr-14 21:31pm
v3

1 solution

   
Comments
fady_hasnaa 15-Apr-14 10:22am
   
no it's firing see in gridvier onrowedite
did you have any idea about the other peoblem ?
manvendra patel 17-Apr-14 1:13am
   
reate table AutoIncrementTable
(
id bigint,
name varchar(50)
)
After creating table now I am going to create a paramentrized stored procedure which insert value in table and
accept name as parameter. This procedure insert id in table automatically and increment id by 1.

Creating parametrized stored procedure

alter proc p_auto_increment_table_proc
@name varchar(50)
as
declare @Id bigint
select @Id=count(Id)+1 from AutoIncrementTable
begin
insert into AutoIncrementTable values(@Id,@name)
end
After creating stored procedure now execute it and see the result.
Executing stored procedure
p_auto_increment_table_proc 'Alok'

This will insert record in table and each time id is automatically incremented.

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




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