15,909,953 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by poongunrans (Top 6 by date)
poongunrans
7-Aug-12 4:53am
View
Could you show us you code, then only help your problem
poongunrans
7-Aug-12 4:50am
View
{ string id = data_list.DataKeys[e.Item.ItemIndex].ToString();
string query = "delete from Book_Candidates where candidate_id='" + id + "'";
SqlConnection theConnection = new SqlConnection(con);
SqlCommand theCommand = new SqlCommand(query, theConnection);
theConnection.Open();
theCommand.ExecuteNonQuery();
theConnection.Close();
Bind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
TextBox tst = (TextBox)e.Item.FindControl("Add_user");
string query = "insert into Book_Candidates(candidate_first_name) values('" + tst .Text+ "')";
SqlConnection theConnection = new SqlConnection(con);
SqlCommand theCommand = new SqlCommand(query, theConnection);
theConnection.Open();
theCommand.ExecuteNonQuery();
theConnection.Close();
Bind();
}
public void Bind()
{
string query = "select candidate_id,candidate_first_name from Book_Candidates";
SqlConnection theConnection = new SqlConnection(con);
SqlCommand theCommand = new SqlCommand(query, theConnection);
SqlDataAdapter da = new SqlDataAdapter(theCommand);
DataSet ds = new DataSet();
da.Fill(ds);
data_list.DataSource = ds;
data_list.DataBind();
}
}
poongunrans
7-Aug-12 4:50am
View
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="datalistall.aspx.cs" Inherits="datalistall" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DataList ID="data_list" runat="server"
OnCancelCommand="DataList1_CancelCommand"
OnDeleteCommand="DataList1_DeleteCommand"
OnEditCommand="DataList1_EditCommand"
OnUpdateCommand="DataList1_UpdateCommand"
OnItemCommand="DataList1_ItemCommand"
DataKeyField="candidate_id">
<itemtemplate>
<div align="center">
<table width="300">
<tr>
<td style="width:60%;"><asp:Label ID="name_lbl" runat="server" Text='<%#Eval("candidate_first_name") %>' /></td>
<td><asp:LinkButton ID="edit_link" runat="server" Text="Edit" CommandName="Edit" /></td>
<td><asp:LinkButton ID="delete_link" runat="server" Text="Delete" CommandName="Delete" /></td>
</tr>
</table>
</div>
<edititemtemplate>
<table width="300">
<tr>
<td style="width:60%;"><asp:TextBox ID="user_txt" runat="server" Text='<%#Eval("candidate_first_name") %>' /></td>
<td><asp:LinkButton ID="update_link" runat="server" CommandName="Update" Text="Update" /></td>
<td><asp:LinkButton ID="cancel_link" runat="server" CommandName="Cancel" Text="Cancel" /></td>
</tr>
</table>
<HeaderTemplate>
<table width="300">
<tr>
<td style="width:60%;">Uer Name</td>
<td colspan="2">Action</td>
</tr>
</table>
</HeaderTemplate>
<footertemplate>
<table width="300">
<tr>
<td style="width:60%;"><asp:TextBox ID="Add_user" runat="server" Text='<%#Eval("candidate_first_name") %>' /></td>
<td colspan="2"><asp:LinkButton ID="Add_link" runat="server" CommandName="Insert" Text="Insert" /></td>
</tr>
</table>
</table>
</div>
</form>
</body>
</html>
server coding
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class datalistall : System.Web.UI.Page
{
string con = ConfigurationSettings.AppSettings["vivaagaConnectionString"];
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
data_list.EditItemIndex = e.Item.ItemIndex;
Bind();
}
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
string id = data_list.DataKeys[e.Item.ItemIndex].ToString();
TextBox tst = (TextBox)e.Item.FindControl("user_txt");
string query = "update Book_Candidates set candidate_first_name='" + tst .Text+ "' where candidate_id='" + id + "'";
SqlConnection theConnection = new SqlConnection(con);
SqlCommand theCommand = new SqlCommand(query, theConnection);
theConnection.Open();
theCommand.ExecuteNonQuery();
theConnection.Close();
data_list.EditItemIndex = -1;
Bind();
}
protected void DataList1_CancelCommand(object source, DataListCommandEventArgs e)
{
data_list.EditItemIndex = -1;
Bind();
}
protected void DataList1_DeleteCommand(object source, DataListCommandE
poongunrans
7-Aug-12 3:42am
View
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string con=ConfigurationSettings.AppSettings["vivaagaConnectionString"]
protected void Page_Load(object sender, EventArgs e)
{
}
protected void AddListItem_Click(object sender, EventArgs e)
{
string query="select user_id,user_name from user where active_flag='A'";
SqlConnection theConnection = new SqlConnection(con);
SqlCommand theCommand=new SqlCommand(query,theConnection);
SqlDataAdapter da=new SqlDataAdapter(theCommand);
DataSet ds=new DataSet();
da.Fill(ds);
Add_lst.DataTextField="user_name";
Add_lst.DataValueField="user_id";
Add_lst.DataSource=ds;
Add_lst.DataBind();
}
}
poongunrans
7-Aug-12 3:35am
View
Added your coding with in update pannel.. then only without refers the page
poongunrans
7-Aug-12 3:25am
View
Client Coding
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
Add a List Event Button Click Event
<div style="padding-left:80px; padding-top:20px;">
<table>
<tr>
<td><span style="color:Green; font-size:14px; font-weight:bold;"><asp:Label ID="Msg_lbl" runat="server"></span></td>
</tr>
<tr>
<td> <asp:ListBox ID="Add_lst" runat="server"> </td>
</tr>
<tr>
<td><asp:Button ID="Add_but" runat="server" Text="Add" OnClick="AddListItem_Click" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Server Coding
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
private static int counter = 0;
protected void Page_Load(object sender, EventArgs e)
{
counter++;
}
protected void AddListItem_Click(object sender, EventArgs e)
{
Add_lst.Items.Add("List Item " + counter);
Msg_lbl.Text = "List Item " + counter + " Added Successfully";
}
}
All the best....
Thanks and Regards
By
Poongunran S
Show More