C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




can anyone solve this issue?


Posted Date: 20 Aug 2008      Total Responses: 1

Posted By: spandhanaspandy       Member Level: Gold     Points: 1


I have binded the data to the datagrid control by using datatable.Now, i want to edit the data in the datagrid. Can anyone tell me?

The following code which i have done for binding data,

1)popup.aspx.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body onunload="opener.location.reload();">
<form id="form1" runat="server">
<div>
UserName:
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><br />
FirstName:<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox><br />
LastName:<asp:TextBox ID="txtLastName" runat="server"></asp:TextBox> <br />
<asp:Button ID="BtnAdd" runat="server" Text="Add User" OnClick="BtnAdd_Click" />
<asp:Button ID="Btn_CloseWindow" runat="server" Text="Close Window" /></div>
</form>
</body>
</html>
********************************************************************************
2)popup.aspx.cs

public partial class popup: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) { }
}

protected void BtnAdd_Click(object sender, EventArgs e)
{
AddNewData();
}


public void AddNewData()
{
DataTable dt=new DataTable();
if(Session["myDatatable"]!=null)
{
dt=(DataTable)Session["myDatatable"];
}
else
{
dt.Columns.Add("UserName");
dt.Columns.Add("FirstName");
dt.Columns.Add("LastName");
}
DataRow drow=dt.NewRow();
drow["UserName"]=txtUserName.Text.ToString();
drow["FirstName"]=txtFirstName.Text.ToString();
drow["LastName"]=txtLastName.Text.ToString();

dt.Rows.Add(drow);

Session["myDatatable"]=dt;
}

}
****************************************************************************************
3)gridpage.aspx

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="refresh" content="600" />
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
<br />
<a href="#" onclick="OpenWindow()">Enter Data</a></div>
<br />
</form>
</body>
</html>

<script language="javascript" type="text/javascript">

function OpenWindow()
{

window.open ("popup.aspx",
"mywindow","menubar=0,resizable=0,width=350,height=250,toolbars=0");
}
</script>
***************************************************************************************
4)gridpage.aspx.cs

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BindMyGridview();

}
public void BindMyGridview()
{
if (Session["myDatatable"] != null)
{
DataTable dt = (DataTable)Session["myDatatable"];

if ((dt != null) && (dt.Rows.Count > 0))
{
GridView1.Visible = true;
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
GridView1.Visible = false;
}
}
}
}




Responses

Author: shanmukha kumari    21 Aug 2008Member Level: GoldRating:     Points: 6
In addition to deleting a GridView's underlying data, another common need is to allow end users to edit the data displayed in a GridView. With ASP.NET 1.x's DataGrid control, editing the data is certainly possible, but requires creating three event handlers and writing a dozen or so lines of code. With the GridView and ASP.NET 2.0, it is possible to create an editable GridView without writing a single line of code! All of the necessary functionality is encapsulated within the GridView.

The GridView allows editing on a row-by-row basis. An editable GridView contains an additional column with an Edit button in each row. When the end user clicks on an Edit button that row becomes editable, causing the Edit button to change to Update and Cancel buttons and the other columns to become TextBoxes. The end user can then update one or more column values and click Update to save their changes.

In this section we'll examine four examples. Our first demo will look at how to create an editable GridView whose data comes from a SqlDataSource. Next, we'll see how to create an editable GridView from an ObjectDataSource. As you may have guessed, when creating an editable GridView whose data comes from an ObjectDataSource, the underlying data access layer class must provide an appropriate Update method. We'll look at the required signature for the Update method and see how to configure the ObjectDataSource to use this method. In the last two demos we'll see how to customize the editing interface for a GridView column. By default, the TextBoxes have no validation controls associated with them, but your business rules might require certain validation. A particular field may be required or might need to be entered in a specific format. Additionally, the standard TextBox as an editing interface might not be acceptable; we'll also look at an example that replaces the TextBox with a databound DropDownList.

Editing GridView Data That Comes From a SqlDataSource
Creating an editable GridView whose data comes from a SqlDataSource is amazingly easy. To start, the GridView's SqlDataSource must contain an UpdateCommand with appropriate parameters. As we saw in the Deleting a GridView's Underlying Data section, creating such a SqlDataSource is as simple as checking the Generate Insert, Update, and Delete Statements from the dialog box shown back in Figure 35. (Recall that this dialog box is accessed through the second step of the SqlDataSource wizard, by clicking the Advanced button.)

As with the delete example, checking the Generate Insert, Update, and Delete Statements will create not only an UPDATE statement, but INSERT and DELETE statements as well. These can be safely removed if you are creating a GridView that's limited to just editing the existing data. Once you have configured a SqlDataSource with an UPDATE statement, creating an editable GridView is a breeze. Just add a new GridView to the page and, from its Smart Tag, click the Enable Editing checkbox (see Figure 39). This will add a CommandField to the GridView with an Edit button.

see the below link you have a clear idea.

http://msdn.microsoft.com/en-us/library/ms972948.aspx



Post Reply
You must Sign In to post a response.
Next : please give me the code....pls....
Previous : dropdown asp.net control
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use