Hai Friends,
How can we bind empty Textbox to datalist in asp.net.So that i can enter data in that textbox if click on submit the enterd data will saved to database.If i Open next time that should display in label and new empty textbox should apper for entering new data.
Regards
Divya
Loading

Iftikar HussainPosted Aug 12, 2013, 6:01 AM
http://stackoverflow.com/questions/206983/putting-a-gridview-row-in-edit-mode-programmatically
Regards,
Iftikar
Sanjeeb LenkaPosted Aug 12, 2013, 5:40 AM
or check this code:
in aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
in .cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class Default3 : System.Web.UI.Page
{
string connectionString = "Data Source=SYSTEM-30;database=DB_Test_Trainees;user id=test;password=Test";
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}
private void Bind()
{
SqlConnection conn = new SqlConnection(connectionString);
SqlDataAdapter ad = new SqlDataAdapter("select * from deptdhii", conn);
DataSet ds = new DataSet();
conn.Open();
ad.Fill(ds);
conn.Close();
DataList1.DataSource = ds.Tables[0];
DataList1.DataBind();
}
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("Insert"))
{
TextBox txtCustNo = (TextBox)e.Item.FindControl("txtCustNo");
TextBox txtCustName = (TextBox)e.Item.FindControl("txtCustName");
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "Insert into DEPTDHII(deptno,dname) values(@1,@2)";
cmd.Parameters.AddWithValue("@1", txtCustNo.Text);
cmd.Parameters.AddWithValue("@2", txtCustName.Text);
conn.Open();
cmd.ExecuteNonQuery();
ClientScript.RegisterStartupScript(GetType(), "ShowAlert", "alert('Record Added Succesfully');", true);
conn.Close();
Bind();
}
}
}
any problem reply
divyaPosted Aug 12, 2013, 5:35 AM
Regards,
Divya
Sanjeeb LenkaPosted Aug 12, 2013, 5:27 AM
http://navoneel23.blogspot.in/2013/04/aspnet-datalist-insert-update-delete.html
http://www.c-sharpcorner.com/uploadfile/anjudidi/add-delete-and-update-command-in-datalist/
Iftikar HussainPosted Aug 12, 2013, 3:57 AM
Please refer the below link
http://msdn.microsoft.com/en-us/library/90xwe9s3(v=vs.100).aspx
http://www.asp.net/web-forms/tutorials/data-access/editing-and-deleting-data-through-the-datalist/an-overview-of-editing-and-deleting-data-in-the-datalist-cs
Regards,
Iftikar