private
void
dg_infoKind_CancelCommand(
object
source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dg_infoKind.EditItemIndex = - 1 ;
this .bindGrid();
}
private void dg_infoKind_EditCommand( object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this .dg_infoKind.EditItemIndex = e.Item.ItemIndex;
this .bindGrid();
}
private void dg_infoKind_ItemCommand( object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == " delete " )
{
if (dType.Delete(dg_infoKind.DataKeys[e.Item.ItemIndex].ToString()))
{
this .lbl_message.Text = " 删除成功! " ;
this .lbl_message.ForeColor = Color.Green;
this .bindGrid();
}
else
{
this .lbl_message.Text = " 删除失败! " ;
this .lbl_message.ForeColor = Color.Red;
}
}
}
catch
{
this .lbl_message.Text = " 删除失败!此项在本系统其他地方引用,请先删除! " ;
this .lbl_message.ForeColor = Color.Red;
}
}
private void dg_infoKind_ItemDataBound( object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Footer && e.Item.ItemType != ListItemType.Header)
e.Item.Cells[ 3 ].Attributes.Add( " onclick " , " return confirm('你将删除这条记录,是否继续?'); " );
}
private void dg_infoKind_UpdateCommand( object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
string id = dg_infoKind.DataKeys[e.Item.ItemIndex].ToString();
string Name = ((TextBox)(e.Item.Cells[ 1 ].Controls[ 0 ])).Text;
if (dType.Update(id,Name))
{
this .lbl_message.Text = " 修改成功! " ;
this .lbl_message.ForeColor = Color.Green;
dg_infoKind.EditItemIndex = - 1 ;
this .bindGrid();
}
else
{
this .lbl_message.Text = " 修改失败! " ;
this .lbl_message.ForeColor = Color.Red;
}
}
catch
{
this .lbl_message.Text = " 修改失败! " ;
this .lbl_message.ForeColor = Color.Red;
}
}
{
dg_infoKind.EditItemIndex = - 1 ;
this .bindGrid();
}
private void dg_infoKind_EditCommand( object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this .dg_infoKind.EditItemIndex = e.Item.ItemIndex;
this .bindGrid();
}
private void dg_infoKind_ItemCommand( object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
if (e.CommandName == " delete " )
{
if (dType.Delete(dg_infoKind.DataKeys[e.Item.ItemIndex].ToString()))
{
this .lbl_message.Text = " 删除成功! " ;
this .lbl_message.ForeColor = Color.Green;
this .bindGrid();
}
else
{
this .lbl_message.Text = " 删除失败! " ;
this .lbl_message.ForeColor = Color.Red;
}
}
}
catch
{
this .lbl_message.Text = " 删除失败!此项在本系统其他地方引用,请先删除! " ;
this .lbl_message.ForeColor = Color.Red;
}
}
private void dg_infoKind_ItemDataBound( object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType != ListItemType.Footer && e.Item.ItemType != ListItemType.Header)
e.Item.Cells[ 3 ].Attributes.Add( " onclick " , " return confirm('你将删除这条记录,是否继续?'); " );
}
private void dg_infoKind_UpdateCommand( object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
string id = dg_infoKind.DataKeys[e.Item.ItemIndex].ToString();
string Name = ((TextBox)(e.Item.Cells[ 1 ].Controls[ 0 ])).Text;
if (dType.Update(id,Name))
{
this .lbl_message.Text = " 修改成功! " ;
this .lbl_message.ForeColor = Color.Green;
dg_infoKind.EditItemIndex = - 1 ;
this .bindGrid();
}
else
{
this .lbl_message.Text = " 修改失败! " ;
this .lbl_message.ForeColor = Color.Red;
}
}
catch
{
this .lbl_message.Text = " 修改失败! " ;
this .lbl_message.ForeColor = Color.Red;
}
}
为dropdownlist赋值:
html代码:
<
asp:DropDownList
id
=DropDownList2
runat
="server"
Width
="100px"
SelectedValue
='<%#
DataBinder.Eval(Container, "DataItem.userType") %
>
'>
< asp:Label id =Label1 runat ="server" Text ='<%# DataBinder.Eval(Container, "DataItem.typeName")% > '>
< asp:Label id =Label1 runat ="server" Text ='<%# DataBinder.Eval(Container, "DataItem.typeName")% > '>