TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
wyndel villanueva
NA
14
17.4k
Update Gridview
Oct 22 2012 12:13 AM
Please help to find what makes not update when i editing my gridview.
See below for my gridview, codings and stored procedure.
//Gridview
<asp:GridView ID="user_gridview2"
runat="server"
AllowPaging="True"
cellpadding="5"
DataKeyNames="Agent_code"
onrowediting="user_RowEditing"
onrowcancelingedit="user_RowCancelingEdit"
OnRowDeleting="user_RowDeleting"
OnRowUpdating="user_Rowupdating"
Onpageindexchanging="user_PageIndexChanging"
onsorting="user_Sorting"
AutoGenerateColumns="False"
AllowSorting="True"
AutoGenerateEditButton="True"
AutoGenerateDeleteButton="True"
EmptyDataText="There are no data records to display.">
<PagerSettings Mode="NumericFirstLast" PageButtonCount="4" FirstPageText="First" LastPageText="Last"/>
<RowStyle BackColor="White" ForeColor="#333333" Height="30px" BorderWidth="1px" VerticalAlign="Top"/>
<FooterStyle BackColor="#99CCFF" Font-Bold="True" ForeColor="White" BorderStyle="None" Wrap="False" />
<PagerStyle BackColor="#0099CC" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" Height="35px" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#0099CC" Font-Bold="True" ForeColor="White" Height="40px"/>
<editrowstyle BackColor="#0099CC" verticalalign="Top" />
<AlternatingRowStyle BackColor="#99CCFF" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="label1" runat="server" Text='<%# Eval("Camp_id") %>' >
</asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:DropDownList ID="DropDownList1" runat="server" >
<asp:ListItem></asp:ListItem>
<asp:ListItem>GM001</asp:ListItem>
<asp:ListItem>GM002</asp:ListItem>
<asp:ListItem>GM003</asp:ListItem>
<asp:ListItem>GM004</asp:ListItem>
<asp:ListItem>GM005</asp:ListItem>
</asp:DropDownList>
<%-- <asp:TextBox ID="DropDownList1" runat="server" Text='<%#
Eval("Camp_id") %>' ></asp:TextBox>--%>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Call Center">
<ItemTemplate >
<asp:Label ID="Label" runat="server" Text='<%# Eval("Call_Center") %>' >
</asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:DropDownList ID="DropDownList2" runat="server" >
<asp:ListItem></asp:ListItem>
<asp:ListItem>U.S EASTCOAST</asp:ListItem>
<asp:ListItem>U.S WESTCOAST</asp:ListItem>
<asp:ListItem>JAPAN</asp:ListItem>
</asp:DropDownList>
<%--<asp:TextBox ID="DropDownList2" runat="server" Text='<%#
Eval("Call_Center") %>' ></asp:TextBox>--%>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Agent Code">
<ItemTemplate>
<asp:Label ID="Label" runat="server" Text='<%# Eval
("Agent_code") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="TextBox2" runat="server" Text='<%#
Eval("Agent_code") %>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Agent Password">
<ItemTemplate>
<asp:Label ID="Label" runat="server" Text='<%# Eval
("Agent_Pass") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Lastname">
<ItemTemplate>
<asp:Label ID="Label" runat="server" Text='<%# Eval
("Agent_Lastname") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="TextBox4" runat="server" Text='<%#
Eval("Agent_Lastname") %>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Firstname">
<ItemTemplate>
<asp:Label ID="Label" runat="server" Text='<%# Eval
("Agent_Firstname") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:TextBox ID="TextBox5" runat="server" Text='<%#
Eval("Agent_Firstname") %>' ></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="User Type">
<ItemTemplate>
<asp:Label ID="Label" runat="server" Text='<%# Eval
("User_type") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:DropDownList ID="DropDownList3" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Agent</asp:ListItem>
<asp:ListItem>Team Leader</asp:ListItem>
<asp:ListItem>Supervisor</asp:ListItem>
</asp:DropDownList>
<%-- <asp:TextBox ID="DropDownList3" runat="server" Text='<%#
Eval("User_type") %>' ></asp:TextBox>--%>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:Label ID="Label" runat="server" Text='<%# Eval
("Status") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate >
<asp:DropDownList ID="DropDownList4" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Active</asp:ListItem>
<asp:ListItem>In-Active</asp:ListItem>
</asp:DropDownList>
<%--<asp:TextBox ID="DropDownList4" runat="server" Text='<%#
Eval("Status") %>' ></asp:TextBox>--%>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
//Code
protected void user_Rowupdating(object sender, GridViewUpdateEventArgs e)
{
//Retrieve the table from the session object.
DataTable dt = (DataTable)Session["user_gridview2"];
string campcode = user_gridview2.DataKeys[e.RowIndex].Value.ToString();
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["datastore"]);
SqlCommand cmd = new SqlCommand("update_edit_user", conn);
cmd.Connection = conn;
//Update the values.
GridViewRow row = (GridViewRow)user_gridview2.Rows[e.RowIndex];
DropDownList DropDownList1 = (DropDownList)row.FindControl("DropDownList1");
DropDownList DropDownList2 = (DropDownList)row.FindControl("DropDownList2");
TextBox TextBox2 = (TextBox)row.FindControl("TextBox2");
//TextBox TextBox3 = (TextBox)row.FindControl("TextBox3");
TextBox TextBox4 = (TextBox)row.FindControl("TextBox4");
TextBox TextBox5 = (TextBox)row.FindControl("TextBox5");
DropDownList DropDownList3 = (DropDownList)row.FindControl("DropDownList3");
DropDownList DropDownList4 = (DropDownList)row.FindControl("DropDownList4");
try
{
conn.Open();
//cmd.CommandText = "update_edit_user";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Camp_id", SqlDbType.NVarChar, 50).Value = DropDownList1.Text.Trim();
cmd.Parameters.Add("@Call_Center", SqlDbType.NVarChar, 50).Value = DropDownList2.Text.Trim();
cmd.Parameters.Add("@Agent_code", SqlDbType.NVarChar, 50).Value = TextBox2.Text.Trim();
cmd.Parameters.Add("@Agent_Lastname", SqlDbType.NVarChar, 50).Value = TextBox4.Text.Trim();
cmd.Parameters.Add("@Agent_Firstname", SqlDbType.NVarChar, 50).Value = TextBox5.Text.Trim();
cmd.Parameters.Add("@User_type", SqlDbType.NVarChar, 50).Value = DropDownList3.Text.Trim();
cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 50).Value = DropDownList4.Text.Trim();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
//lblMessage.Text = "Record Updated successfully";
//Refresh the data
user_gridview2.EditIndex = -1;
bindGrid();
}
catch (Exception ee)
{
lblMessage.Text = ee.Message.ToString();
}
finally
{
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
public void bindGrid()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["datastore"]);
SqlDataAdapter da = new SqlDataAdapter("select * from P_crm_user", conn);
DataSet ds = new DataSet();
try
{
da.Fill(ds, "P_crm_user");
user_gridview2.DataSource = ds.Tables["P_crm_user"].DefaultView;
user_gridview2.DataBind();
}
catch (Exception ee)
{
lblMessage.Text = ee.Message.ToString();
}
finally
{
ds.Dispose();
ds.Dispose();
conn.Close();
conn.Dispose();
}
}
//Stored Procedure
USE [P_CRM]
GO
/****** Object: StoredProcedure [dbo].[update_edit_user] Script Date: 10/22/2012 11:20:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[update_edit_user]
-- Add the parameters for the stored procedure here
--@rid int
@Camp_Id nvarchar(max)
,@Call_Center nvarchar(max)
,@Agent_code nvarchar(max)
,@Agent_Lastname nvarchar(max)
,@Agent_Firstname nvarchar(max)
,@User_type nvarchar(max)
,@Status nvarchar(max)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
if @Status ='Update'
-- Insert statements for procedure here
UPDATE [P_CRM].[dbo].[P_crm_user]
SET
Agent_code = Agent_code
where Camp_Id=@Camp_Id and @Call_Center= Call_Center and Agent_code=@Agent_code and Agent_Lastname = @Agent_Lastname and Agent_Firstname = Agent_Firstname and @User_type = User_type and Status = @Status
END
thanks in advance :)
Reply
Answers (
1
)
Using JQuery in ASP.NET's master page
ASP.NET Controlls