I am facing a problem while clicking edit button of a gridview.after clicking edit button it is displaying empty textboxes. I need old values in that textboxes.
Here i used 3-tier architecture. Below is my code: - /***Application layer***/
-
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
-
{
-
-
GridView2.EditIndex = e.NewEditIndex;
-
GridView2.DataSource = rigobj.getgvdata();
-
GridView2.DataBind();
-
}
-
-
/***Business layer***/
-
public DataTable getgvdata()
-
{
-
return sdb.ds.Tables["rig_mstr_tab"];
-
}
-
-
/***Data layer***/
-
public shoredatabase()
-
{
-
da = new SqlDataAdapter("select * from rig_mstr_tab", con);
-
da.Fill(ds, "rig_mstr_tab");
-
da.FillSchema(ds, SchemaType.Source, "rig_mstr_tab");
-
bldr = new SqlCommandBuilder(da);
-
}
11 4446
I cannot open the attachment you posted. Please post the method that handles the GridView's RowEditing event.
@Frinavale
Hi Frinavale.. Thanks for your response.can you pls tell me the solution how to do this..now i am attached the file which in (.txt) format..in that file i kept GridView's RowEditing event method.once again thank u very much..we are waiting your reply....bye
I cannot open attachments.
Just post the relevant code to your problem in the thread so that I can see it :)
@bala venkata siva ram kum
Hi kub thank u for editing my post.This time i will read the posting guidelines while i am posting question.But i didn't get answer for my question.what should i do.please tell me the solution.
Hi Frinavale i am sending my code.Here i used 3-tier architecture.after clicking edit button of a Gridview it is displaying empty textboxes.i need old values in those textboxes please tell me the solution. -
-
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
-
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
-
OnRowDeleting="GridView2_RowDeleting" OnRowEditing="GridView2_RowEditing"
-
OnRowCancelingEdit="GridView2_RowCancelingEdit"
-
OnRowUpdating="GridView2_RowUpdating">
-
<Columns>
-
<asp:TemplateField HeaderText="SupplierId">
-
<ItemTemplate>
-
<asp:Label ID="Label1" runat="server" Text='<%# Bind("sup_id") %>'></asp:Label>
-
</ItemTemplate>
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="SupplierName">
-
<EditItemTemplate>
-
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
-
</EditItemTemplate>
-
<ItemTemplate>
-
<asp:Label ID="Label2" runat="server" Text='<%# Bind("sup_name") %>'></asp:Label>
-
</ItemTemplate>
-
</asp:TemplateField>
-
<asp:TemplateField HeaderText="ProductName">
-
<EditItemTemplate>
-
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
-
</EditItemTemplate>
-
<ItemTemplate>
-
<asp:Label ID="Label3" runat="server" Text='<%# Bind("prod_name") %>'></asp:Label>
-
</ItemTemplate>
-
</asp:TemplateField>
-
</Columns>
-
</asp:GridView>
/** c#: **/ -
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;
-
using System.Collections.Generic;
-
using rigBLL;
-
public partial class Default3 : System.Web.UI.Page
-
{
-
sup_mstr_tab supobj = new sup_mstr_tab();
-
protected void Page_Load(object sender, EventArgs e)
-
{
-
if (IsPostBack == false)
-
{
-
GridView2.DataSource = supobj.getgvdata();
-
GridView2.DataBind();
-
}
-
}
-
protected void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
-
{
-
GridView2.EditIndex = -1;
-
GridView2.DataSource = supobj.getgvdata();
-
GridView2.DataBind();
-
}
-
protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
-
{
-
Label lb = (Label)GridView2.Rows[e.RowIndex].FindControl("Label1");
-
supobj.spid =Int32.Parse(lb.Text);
-
supobj.deleterecord();
-
GridView2.DataSource = supobj.getgvdata();
-
GridView2.DataBind();
-
}
-
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
-
{
-
GridView2.EditIndex = e.NewEditIndex;
-
GridView2.DataSource = supobj.getgvdata();
-
GridView2.DataBind();
-
}
-
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
-
{
-
Label lb = (Label)GridView2.Rows[e.RowIndex].FindControl("Label1");
-
TextBox tx1 = (TextBox)GridView2.Rows[e.RowIndex].FindControl("TextBox1");
-
TextBox tx2 = (TextBox)GridView2.Rows[e.RowIndex].FindControl("TextBox2");
-
supobj.spid = Int32.Parse(lb.Text);
-
supobj.spname= tx1.Text;
-
supobj.prname = tx2.Text;
-
supobj.updaterecord();
-
GridView2.EditIndex = -1;
-
GridView2.DataSource = supobj.getgvdata();
-
GridView2.DataBind();
-
}
-
}
/**classlibrary file**/(Business layer) -
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
using System.Data;
-
using clibDAL;
-
-
namespace rigBLL
-
{
-
public class sup_mstr_tab
-
{
-
DataRow rec;
-
shoredatabase sdb = new shoredatabase();
-
int sid;
-
string supname, productname;
-
public int spid
-
{
-
set { sid = value; }
-
}
-
public string spname
-
{
-
set { supname = value; }
-
get { return supname; }
-
}
-
public string prname
-
{
-
set { productname = value; }
-
get { return productname; }
-
}
-
public void insertrecord()
-
{
-
rec=sdb.ds.Tables["sup_mstr_tab"].NewRow();
-
rec[1] = supname;
-
rec[2] = productname;
-
sdb.ds.Tables["sup_mstr_tab"].Rows.Add(rec);
-
sdb.updateDB();
-
-
}
-
public void deleterecord()
-
{
-
rec = sdb.ds.Tables["sup_mstr_tab"].Select("sup_id='" + sid + "'")[0];
-
rec.Delete();
-
sdb.updateDB();
-
-
}
-
public void updaterecord()
-
{
-
rec = sdb.ds.Tables["sup_mstr_tab"].Select("sup_id='" + sid + "'")[0];
-
rec[1] = supname;
-
rec[2] = productname;
-
sdb.updateDB();
-
}
-
public DataTable getgvdata()
-
{
-
return sdb.ds.Tables["sup_mstr_tab"];
-
}
-
-
}
-
}
-
/**class library file**/(data layer)
-
-
using System;
-
using System.Collections.Generic;
-
using System.Linq;
-
using System.Text;
-
using System.Data;
-
using System.Data.SqlClient;
-
-
namespace clibDAL
-
{
-
public class shoredatabase
-
{
-
SqlConnection con = new SqlConnection("Data Source=VC8;Initial Catalog=shore;Integrated Security=True");
-
SqlDataAdapter da,da1,da2,da3,da4,da5,da6;
-
public DataSet ds;
-
SqlCommandBuilder bldr, bldr1, bldr2,bldr3,bldr4,bldr5;
-
public shoredatabase()
-
{
-
-
da = new SqlDataAdapter("select * from rig_mstr_tab", con);
-
da1 = new SqlDataAdapter("select * from ship_mstr_tab", con);
-
da2 = new SqlDataAdapter("select * from sup_mstr_tab", con);
-
da3 = new SqlDataAdapter("select * from imp_mstr_tab order by imp_type", con);
-
da4 = new SqlDataAdapter("select * from meas_mstr_tab", con);
-
da5 = new SqlDataAdapter("select *from bck_mstr_tab", con);
-
ds = new DataSet();
-
-
// insert into rig master table
-
da.Fill(ds, "rig_mstr_tab");
-
da.FillSchema(ds, SchemaType.Source, "rig_mstr_tab");
-
bldr = new SqlCommandBuilder(da);
-
-
//insert into ship master table
-
da1.Fill(ds, "ship_mstr_tab");
-
da1.FillSchema(ds, SchemaType.Source, "ship_mstr_tab");
-
bldr1 = new SqlCommandBuilder(da1);
-
-
//insert into supplier master table
-
da2.Fill(ds, "sup_mstr_tab");
-
da2.FillSchema(ds, SchemaType.Source, "sup_mstr_tab");
-
bldr2 = new SqlCommandBuilder(da2);
-
-
//insert into import master table
-
da3.Fill(ds, "imp_mstr_tab");
-
da3.FillSchema(ds, SchemaType.Source, "imp_mstr_tab");
-
bldr3 = new SqlCommandBuilder(da3);
-
-
//insert into measurement master table
-
da4.Fill(ds, "meas_mstr_tab");
-
da4.FillSchema(ds, SchemaType.Source, "meas_mstr_tab");
-
bldr4 = new SqlCommandBuilder(da4);
-
-
//insert into backload master table
-
da5.Fill(ds, "bck_mstr_tab");
-
da5.FillSchema(ds, SchemaType.Source, "bck_mstr_tab");
-
bldr5 = new SqlCommandBuilder(da5);
-
-
-
-
}
-
public void updateDB()
-
{
-
da.Update(ds, "rig_mstr_tab");
-
da1.Update(ds, "ship_mstr_tab");
-
da2.Update(ds, "sup_mstr_tab");
-
da3.Update(ds, "imp_mstr_tab");
-
da4.Update(ds, "meas_mstr_tab");
-
da5.Update(ds, "bck_mstr_tab");
-
}
-
}
-
-
}
-
-
You see how you are biding the text to the Label in your code?
Do the same thing for the TextBoxes and it will work the way you want it to :)
-Frinny
Hi Frinny, sorry i went to chennai for the last three days.
i saw your reply and i tried as you told and some error is coming while assigning text to textboxes.I am sending that code.please send me the code how to assign into textboxes while editing gridview. -
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
-
{
-
Label lb1 = (Label)GridView2.Rows[e.NewEditIndex].FindControl("Label2");
-
Label lb2 = (Label)GridView2.Rows[e.NewEditIndex].FindControl("Label3");
-
-
GridView2.EditIndex = e.NewEditIndex;
-
(TextBox)GridView2.Rows[e.NewEditIndex].FindControl("TextBox1") = lb1.Text;//(It is showing error asThe left-hand side of an assignment must be a variable, property or indexer)
-
GridView2.DataSource = supobj.getgvdata(); //(cannot implicitly convert type 'string' to 'system.web.UI.webcontrols.textbox')
-
GridView2.DataBind();
-
}
-
You are attempting to assign a String to a control that has been located in the GridView. This obviously doesn't make sense, you should be assigning the string to the Text property of the control.
Changing it to the following will work: -
(TextBox)GridView2.Rows[e.NewEditIndex].FindControl("TextBox1").Text = lb1.Text;
But it would be better to check that the TextBox1 exists before attempting to use it: -
if((TextBox)GridView2.Rows[e.NewEditIndex].FindControl("TextBox1") !=null){
-
(TextBox)GridView2.Rows[e.NewEditIndex].FindControl("TextBox1").Text = lb1.Text;
-
}
-Frinny
@Frinavale
Hi Frinny,Good Morning thank q so much.you have solved my problem.
@bala
It seems you set your last reply to frinny as the best answer in error. I have reset it to allow you to correctly set which post you consider to be the best answer.
Mary
ok,it is better check the condition. Thanq
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Alex |
last post by:
I have a datagrid with two additional columns (edit, delete).
However the edit and delete handlers in the code behind page are never
reached.
When I click on the delete or edit button the load...
|
by: Mike P |
last post by:
How do you disable the edit button for selected rows in a gridview?
Here is my button :
<asp:CommandField ShowEditButton="True" ButtonType="Link"
ShowCancelButton="True"
UpdateText="Update"...
|
by: Damien |
last post by:
Hi,
I have a added an edit button to my gridview and when i click it once the
page refreshes but i have to click it again for the textbox to appear, this
same problem as exists for the update.
...
|
by: karups |
last post by:
Hi
I have binded a dataset to my datagrid.
Datagrid is present inside a >DIV></DIVtag of specific height.
Only 5 records will be visible at a time
when i edit the 10th record, the page...
|
by: Not Me |
last post by:
Hi there,
How come, when using default settings on a gridview which has a stored
procedure as it's datasource's selectcommand, do I have to sort the
stored procedure in order to have the edit...
|
by: ruthie |
last post by:
Hi,
I have a gridview with edit option. If the user chooses to edit the
row and then press the Cancel button - I would like the focus to
return to the chosen row.
Someone has any idea how to...
|
by: =?Utf-8?B?Ym9iYnk=?= |
last post by:
Hi,
I have GridView. I set AutoGenerateEditButton="True" . When I click this
button it puts some fields in edit mode. But I want to add button field in
grid View and When I click on that...
|
by: sejal17 |
last post by:
Hello everyone,
I have a problem with taking button in gridview and datalist.In datalist,i have one field to display naming card_price and one button naming BUY.I want to click that BUY...
|
by: DJOuk |
last post by:
Posted this on Asp.Net, seems to be a hard problem, I still can't work it out
I have a edit button, this works fine, until I add the code that prevents the edit button from being seen by users who...
|
by: skuer |
last post by:
Hey people
If I have made a page with login system, are there any possibilities to let a special group of people edit the page or some of the text on the page, just by clicking a edit button on...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |