Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have a webform of Cities where i have a gridview in which i m showing data of city table i.e CityName,CityShortName

when i m searching data its displaying the search data but when i click edit button its not editing the searched data its editing the data which is at index 1 plz help me how can i edit and delete search data

i m using edit delete update event and code behind

thnx
Posted
Comments
NMehta83 13-Oct-10 2:23am    
please add your code snippet of aspx page and code behind page also. To get the exact point where you made the mistake.

1 solution

Check these if you haven't done yet,

1. Make sure you have apply CommandName="Edit" to Edit Button,
2. Make sure automatically EditIndex not setting to 1 itself,
3. Make sure you have performed task with !IsPostBack Condition.

I can figure out these might be the thing you missing, You could put your snippets to have deeper understanding.

Please vote and Accept Answer if it Helped.
 
Share this answer
 
Comments
eraser950 13-Oct-10 2:34am    
this is my complete code behind
" protected void GVCity_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GVCity.PageIndex = e.NewPageIndex;
BindData();
}

protected void GVCity_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GVCity.EditIndex = -1;
BindData();
}

protected void GVCity_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
a = ct.DeleteCity(((int)(GVCity.DataKeys[e.RowIndex].Value)));
BindData();
lblMesg.Text = a;
}

protected void GVCity_RowEditing(object sender, GridViewEditEventArgs e)
{
GVCity.EditIndex = e.NewEditIndex;
BindData();
}

protected void GVCity_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GVCity.Rows[e.RowIndex];
a = ct.UpdateCity(((int)GVCity.DataKeys[e.RowIndex].Value), ((TextBox)(row.Cells[1].Controls[0])).Text, ((TextBox)(row.Cells[2].Controls[0])).Text);

//Reset the edit index.
GVCity.EditIndex = -1;
BindData();
lblMesg.Text = a;
}
public void BindData()
{
string SP = "SelectCity";
DataTable dt = esp.ExecSP(SP);
GVCity.DataSource = dt;
GVCity.DataBind();
lblMesg.Text = string.Empty;
}

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
lblMesg.Text = string.Empty;
}
}
string SP="SearchCity";//store procedure
DataTable dt= sr.ExecSP(SP, txtSearch.Text);//execute //sp //and //return datatable


GVCity.DataSource = dt;

GVCity.DataBind();"

plz tell me wt i m missing
Hiren solanki 13-Oct-10 2:38am    
I can not tell you for sure but you could try

protected void GVCity_RowEditing(object sender, GridViewEditEventArgs e)
{
BindData();
GVCity.EditIndex = e.NewEditIndex;
}
insted of,
protected void GVCity_RowEditing(object sender, GridViewEditEventArgs e)
{
GVCity.EditIndex = e.NewEditIndex;
BindData();
}
eraser950 13-Oct-10 2:43am    
thnx i willl try this
eraser950 13-Oct-10 2:47am    
no dear its not worrking
eraser950 13-Oct-10 2:54am    
is there any way to show all data when i search but just highlight the searched data so that this problem will solve

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