Click here to Skip to main content
15,891,621 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all!
I am developing a web application in asp.net using c# in three tier architecture, I have to manage appointments in one of the modules.
I have three classes Appointments.aspx.cs , AppointmentsBLL, AppointmetnsDAL.

In gridview i have displayed appointments.like :

C#
AppointmentsBLL appointB = new AppointmentsBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            gvAppointmetns.DataSource = appointB.showAppointments();
            gvAppointmetns.DataBind();
        }

BLL code is this:

C#
public DataTable showAppointments()
{
DataTable dtAppoint;
AppointmentsTableAdapter appointAdapt = new   AppointmentsTableAdapter();
dtAppoint = appointAdapt.GetAppointmentsData()
return dtAppoint;
}


I am able to insert records easily but the problem is that I want to update and delete those records as well. for which I have used template field "action" and image buttons "edit" and "delete" are bounded in that template field.Now what I want is: when I click edit button the record of that specific row is selected and appear in the text boxes below, I have tried many options like selected row , datakeynames etc but nothing happens when I click on edit button.I have been successfull in edting and deleting records using sqldatasource and gridview methods but that is not working in three tier, As I am new to asp.net so could anyone kindly guide me. may be I am missing some thing.
method for edit button click is:

C#
protected void ImgBtnEdit_Click(object sender, ImageClickEventArgs e)
{
tb_AppointDate.Text = gvAppointmetns.SelectedRow.Cells[3].Text.ToString();
tb_GName.Text = gvAppointmetns.SelectedRow.Cells[4].Text.ToString();
tb_GDesignation.Text = gvAppointmetns.SelectedRow.Cells[5].Text.ToString();
}


during debugging selected row shows null value inserted.
Thanks in advance.
Posted
Updated 13-Aug-10 0:24am
v2
Comments
koool.kabeer 13-Aug-10 5:25am    
just set the CommandName of your ImageButtons...
as "select"...
that means whenever you click that button the "select" command of GridView fires...
Ankur\m/ 13-Aug-10 6:24am    
Put Code Snippets inside <PRE> tags (Code Block). It increases the readability and maintains indentation.

Hi there,

i suggest using the objectcontainerdatasource-control from ms p&p group.
It behaves similar to sqldatasource but can be bound to your BL-Objects.

The good thing is that you can use the sorting and editing functions
of your grid very easy.

Look here for more information or google with bing for "objectcontainerdatasource patterns and practices".
 
Share this answer
 
v2
just put at aspx page where designing button.

--(CommandArgument='<%# Container.DisplayIndex %>')


and

--(CommandName="Edit")
=========================================================
in cs code inside button click
{

int rowindex1=Convert.ToInt32(e.CommandArgument);

}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900