TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Elshen Zamanov
NA
4
3.4k
Edit, delete and update in gridview
Aug 24 2013 7:58 AM
hi , i have a gridview and i have edit, delete and update buttons.i can use edit and delete buttons they work but update button doesn't work when i click on update button ,the page refreshes ,doesn't update.please help me.here is my code...
<asp:GridView ID="GridviewTeams"
runat="server"
AutoGenerateColumns="false"
OnRowUpdating="GV_RowUpdating"
OnRowDeleting="GV_RowDeleting"
OnRowEditing="GV_RowEditing"
OnRowCancelingEdit="GV_RowCancelingEdit">
<Columns>
<asp:TemplateField HeaderText="ID">
<EditItemTemplate>
<asp:TextBox runat="server" ID="tbx_ID" >
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" ID="GV_lblTeamID" Text='<%# Eval("teamID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Team Name">
<EditItemTemplate>
<asp:TextBox runat="server" ID="tbxEditTeamName" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" ID="lblEditTeamName" Text='<%# Eval("team_name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Team email">
<EditItemTemplate>
<asp:TextBox runat="server" ID="tbxEditTeamEmail" ></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" ID="lbl_edit_stadium_adress" Text='<%# Eval("team_email") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Commands" ShowHeader="False">
<EditItemTemplate>
<asp:LinkButton ID="LnkBtnUpdate" runat="server" CausesValidation="True"
CommandName="Update" Text="Update"></asp:LinkButton>
<asp:LinkButton ID="LnkBtnCancel" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel"></asp:LinkButton>
</EditItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="LnkBtnEdit" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit"></asp:LinkButton>
<asp:LinkButton ID="LnkBtnDelete" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
code behind...
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
public void Bind()
{
try
{
CTeam cTeam = new CTeam();
GridviewTeams.DataSource = cTeam.GetAllTeams();
GridviewTeams.DataBind();
}
catch (Exception err)
{
Response.Write(err.Message);
}
}
protected void BtnAdd_Click(object sender, EventArgs e)
{
CTeam cteam = new CTeam();
cteam.AddTeams(tbxTeamName.Text,tbxTeamEmail.Text);
Bind();
}
protected void GV_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
CTeam cteam = new CTeam();
int indexrow = e.RowIndex;
short tid = short.Parse(((Label)GridviewTeams.Rows[indexrow].FindControl("GV_lblTeamID")).Text);
cteam.DeleteTeams(tid);
Bind();
}
protected void GV_RowEditing(object sender, GridViewEditEventArgs e)
{
GridviewTeams.EditIndex = e.NewEditIndex;
Bind();
}
protected void GV_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridviewTeams.EditIndex = -1;
Bind();
}
protected void GV_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
CTeam cteam = new CTeam();
int indexrow = e.RowIndex;
string tname = ((TextBox)GridviewTeams.Rows[e.RowIndex].FindControl("tbxEditTeamName")).Text;
string temail = ((TextBox)GridviewTeams.Rows[e.RowIndex].FindControl("tbxEditTeamEmail")).Text;
cteam.UpdateTeams(tname, temail);
GridviewTeams.EditIndex = -1;
Bind();
}
}
Reply
Answers (
1
)
how to add image
ListView Or Gridview?