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>
<%----%>
</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>
<%----%>
</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:
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 ;
select @fix_scope_prob=transaction_num from tbl_transaction where transaction_num=@transaction_num ;
update tbl_transaction_service
set qty=@qt
where transaction_num=@fix_scope_prob and service_code=@servicecode ;
select @return_val=@fix_scope_prob ;