在datagridview中编辑的问题 [英] problem in editting in datagridview

查看:110
本文介绍了在datagridview中编辑的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

i有我正在尝试编辑并插入网格中的后续网格

i有一些问题

优先:

当我点击编辑链接按钮时,它在第一次你需要再次点击时不起作用它工作正常。

秒:

在editmode的bindgrid中,行数据绑定找不到dropdownlist这是因为在编辑模式下的dropdownlist名称在itemtemplate中不一样,我不能使它们相同会导致错误重复控制,所以如何绑定网格在编辑模式下还是在插入模式下?

第三:

i有一个存储过程用于编辑和插入相同的sp,它在两个表中插入或更新:master和细节。在主表中插入或更新后,应在详细信息表中执行相同的操作。所以我应该得到scop_identity(),但sql server 2008 scope_identity()中的问题是,它总是返回null,因此不会发生master中的插入或更新

i只是试图找到为什么发生这个问题,我发现在sql server 2008的设置中发生错误导致了这个问题

我该如何解决这个问题?我不知道?

i尝试在主表中创建自动增量列,并获得最大值,这在插入中有效但在更新时不起作用

可以任何一个请帮帮我?

这是我的代码:

gridview:

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: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:









codebehind:


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();




          }

      }










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 ;

推荐答案

you are not firing edit event of grid-view



try this -

http://www.aspsnippets.com/Articles/Simple-Insert-Select-Edit-Update-and-Delete-in-ASPNet-GridView-control.aspx[^]
you are not firing edit event of grid-view

try this -
http://www.aspsnippets.com/Articles/Simple-Insert-Select-Edit-Update-and-Delete-in-ASPNet-GridView-control.aspx[^]


这篇关于在datagridview中编辑的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆