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 button not functioning in gridview
Oct 18 2012 12:41 AM
Please help anyone where in code get me wrong, why update button cant able.
im tired enough of doing it.
help me please.
below are my codes:
// gridview
<asp:Label ID="lblMessage" runat="Server" ForeColor="Red" CssClass="label_cont"></asp:Label>
<asp:GridView ID="user_gridview"
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 HeaderText="Campaign ID">
<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>
</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>
</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>
</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>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
//heres my .cs codes
//########### row updating ###########
protected void user_Rowupdating(object sender, GridViewUpdateEventArgs e)
{
//Retrieve the table from the session object.
//DataTable dt = (DataTable)Session["user_gridview"];
string campid = user_gridview.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_gridview.Rows[e.RowIndex];
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 = int_camp_id.Text.Trim();
cmd.Parameters.Add("@Call_Center", SqlDbType.NVarChar, 50).Value = txt_call_center.Text.Trim();
cmd.Parameters.Add("@Agent_code", SqlDbType.NVarChar, 50).Value = int_agent_code.Text.Trim();
cmd.Parameters.Add("@Agent_Lastname", SqlDbType.NVarChar, 50).Value = txt_agent_lname.Text.Trim();
cmd.Parameters.Add("@Agent_Firstname", SqlDbType.NVarChar, 50).Value = txt_agent_fname.Text.Trim();
cmd.Parameters.Add("@User_type", SqlDbType.NVarChar, 50).Value = txt_user_type.Text.Trim();
cmd.Parameters.Add("@Status", SqlDbType.NVarChar, 50).Value = txt_status.Text.Trim();
cmd.Connection = conn;
cmd.ExecuteNonQuery();
// lblMessage.Text = "Record Updated successfully";
//Refresh the data
user_gridview.EditIndex = -1;
bindGrid();
}
catch (SqlException ee)
{
Response.Write(ee.Message);
}
finally
{
cmd.Dispose();
conn.Close();
conn.Dispose();
}
}
//heres my stored procedure
USE [P_CRM]
GO
/****** Object: StoredProcedure [dbo].[update_edit_user] Script Date: 10/18/2012 12:39:16 ******/
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;
-- 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
.hope anyone can find what is wrong with my codes.
thanks in advance
Reply
Answers (
3
)
Organization Chart in ASP.NET
WORD APPLICATION