行绑定数据后的处理:
protected void gdvQuery_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (this.gdvQuery.EditIndex == -1)
{
string confirmMeg = ManagerBusiness.GetMessageCodeManager.GetMessageByCode("007");
LinkButton lbtnDelete = (LinkButton)e.Row.FindControl("lbtnDelete");
lbtnDelete.Attributes.Add("onclick", "return confirm('" + confirmMeg + "')");
Label lblItemID = (Label)(e.Row.FindControl("lblItemTypeTemp"));
switch (lblItemID.Text.Trim())
{
case "1":
lblItemID.Text = "APPS";
break;
case "2":
lblItemID.Text = "GAMES";
break;
case "3":
lblItemID.Text = "APPS-GAMES";
break;
}
}
else
{
if (e.Row.RowIndex == this.gdvQuery.EditIndex)
{
Label lblItemIDEdit = (Label)(e.Row.FindControl("lblItemTypeEdit"));
DropDownList ddlItemType = (DropDownList)(e.Row.FindControl("ddlItemType"));
ddlItemType.SelectedValue = lblItemIDEdit.Text.Trim();
}
else
{
Label lblItemID = (Label)(e.Row.FindControl("lblItemTypeTemp"));
switch (lblItemID.Text.Trim())
{
case "1":
lblItemID.Text = "APPS";
break;
case "2":
lblItemID.Text = "GAMES";
break;
case "3":
lblItemID.Text = "APPS-GAMES";
break;
}
}
}
}
}
catch (Exception ex)
{
throw;
}
}
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string confirmMeg = ManagerBusiness.GetMessageCodeManager.GetMessageByCode("024");
LinkButton btnRemove = (LinkButton)e.Row.FindControl("btnRemove");
btnRemove.Attributes.Add("onclick", "return confirm('" + confirmMeg + "')");
}
}
catch (Exception ex)
{
throw;
}
删除
protected void gdvPartPartList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
try
{
Label lblItemTemp = (Label)(this.gdvPartPartList.Rows[e.RowIndex].FindControl("lblItemTemp"));
ManagerBusiness.GetPagePartItemListtManager.RemovePagePartItemList(lblItemTemp.Text.Trim(), this.ddlPage.SelectedValue.Trim(), this.ddlPart.SelectedValue.Trim());
PagePartListTable.Rows.RemoveAt(e.RowIndex);
BindPagePartList();
}
catch (Exception ex)
{
throw;
}
}
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblItemTemp" runat="server" Text='<%# Bind("ItemID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
准备编辑
protected void gdvQuery_RowEditing(object sender, GridViewEditEventArgs e)
{
try
{
this.gdvQuery.EditIndex = e.NewEditIndex;
BindQuery();
}
catch (Exception ex)
{
throw;
}
}
更新数据
protected void gdvQuery_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
Label lblItemIDEdit = (Label)(this.gdvQuery.Rows[e.RowIndex].FindControl("lblItemIDEdit"));
TextBox txtItemTitle = (TextBox)(this.gdvQuery.Rows[e.RowIndex].FindControl("txtItemTitle"));
DropDownList ddlItemType = (DropDownList)(this.gdvQuery.Rows[e.RowIndex].FindControl("ddlItemType"));
TextBox txtItemUrl = (TextBox)(this.gdvQuery.Rows[e.RowIndex].FindControl("txtItemUrl"));
TextBox txtFiller = (TextBox)(this.gdvQuery.Rows[e.RowIndex].FindControl("txtFiller"));
TextBox txtContent = (TextBox)(this.gdvQuery.Rows[e.RowIndex].FindControl("txtContent"));
if (string.IsNullOrEmpty(txtItemTitle.Text.Trim()))
{
UIHelper.AlertMessage(this.Page, string.Format(ManagerBusiness.GetMessageCodeManager.GetMessageByCode("004"), "「Item Title」"));
return;
}
if (string.IsNullOrEmpty(ddlItemType.SelectedValue))
{
UIHelper.AlertMessage(this.Page, string.Format(ManagerBusiness.GetMessageCodeManager.GetMessageByCode("004"), "「Item Type」"));
return;
}
if (string.IsNullOrEmpty(txtItemUrl.Text))
{
UIHelper.AlertMessage(this.Page, string.Format(ManagerBusiness.GetMessageCodeManager.GetMessageByCode("004"), "「Detail Web」"));
return;
}
if (string.IsNullOrEmpty(txtFiller.Text.Trim()))
{
UIHelper.AlertMessage(this.Page, string.Format(ManagerBusiness.GetMessageCodeManager.GetMessageByCode("004"), "「Filler」"));
return;
}
ManagerBusiness.GetItemListManager.UpdateItem(lblItemIDEdit.Text.Trim(), txtItemTitle.Text.Trim(), txtContent.Text.Trim(), int.Parse(ddlItemType.SelectedValue), txtItemUrl.Text, txtFiller.Text.Trim(), DateTime.Now);
UIHelper.AlertMessage(this.Page, ManagerBusiness.GetMessageCodeManager.GetMessageByCode("009"));
this.gdvQuery.EditIndex = -1;
BindQuery();
}
catch (Exception ex)
{
throw;
}
}
<asp:TemplateField HeaderText="Item Title">
<EditItemTemplate>
<asp:TextBox ID="txtItemTitle" runat="server" Text='<%# Bind("ItemTitle") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ItemTitle") %>'></asp:Label>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="200px" />
</asp:TemplateField>