<tbody>
<tr>
<td background="../adminimages/2007admin_r4_c7.jpg" height="26"> <STRONG><FONT color="#ffffff">::游戏管理::</FONT></STRONG>
</td>
</tr>
<tr>
<td valign="top" style="font-size:13px;" align="center">
<asp:DataList ID="list" runat="server" DataKeyField="GameClass_ID" OnCancelCommand="list_CancelCommand" OnDeleteCommand="list_DeleteCommand" OnEditCommand="list_EditCommand" OnUpdateCommand="list_UpdateCommand">
<HeaderTemplate>
<td width="50">编号</td>
<td width="210">名称</td>
<td width="80">字母</td>
<td width="80">显示</td>
<td width="200">添加游戏服务区</td>
<td width="50">编辑</td>
<td width="50">删除</td>
</HeaderTemplate>
<ItemTemplate>
<td height="23"><asp:Label ID="lbid" runat="server" Text='<%#Eval("GameClass_ID").ToString().Trim()%>'></asp:Label></td>
<td height="23"><asp:Label ID="lbname" runat="server" Text='<%#Eval("GameClass_Name").ToString().Trim()%>'></asp:Label></td>
<td height="23"><asp:Label ID="lbfristname" runat="server" Text='<%#Eval("GameClass_FristName").ToString().Trim()%>'></asp:Label></td>
<td height="23"><asp:Label ID="lbshow" runat="server" Text='<%#Eval("GameClass_Visible").ToString().Trim()=="1"?"是":"否"%>'></asp:Label></td>
<td height="23"><a href="gamearea.aspx?type=<%#Eval("GameClass_ID").ToString().Trim()%>&game=<%#Eval("GameClass_Name").ToString().Trim()%>">添加游戏服务区</a></td>
<td height="23"><asp:LinkButton ID="lkbedit" CommandName="Edit" runat="server" Text="编辑"></asp:LinkButton> </td>
<td height="23"><asp:LinkButton ID="lkbdelete" CommandName="Delete" runat="server" Text="删除"></asp:LinkButton></td>
</ItemTemplate>
<EditItemTemplate>
<td><asp:Label ID="lb_id" runat="server" Text='<%#Eval("GameClass_ID").ToString().Trim()%>'></asp:Label><asp:Label ID="fristnamehiddle" Visible="false" runat="server" Text='<%#Eval("GameClass_FristName").ToString().Trim()%>'></asp:Label><asp:Label ID="lbshow3" Visible="false" runat="server" Text='<%#Eval("GameClass_Visible").ToString().Trim()%>'></asp:Label><asp:Label ID="namehiddle" Visible="false" runat="server" Text='<%#Eval("GameClass_Name").ToString().Trim()%>'></asp:Label></td>
<td><asp:TextBox ID="txtname" Width="120" runat="server" Text='<%#Eval("GameClass_Name").ToString().Trim()%>'></asp:TextBox></td>
<td><asp:DropDownList ID="dd_fristname" Width="60" runat="server">
<asp:ListItem>A</asp:ListItem>
<asp:ListItem>B</asp:ListItem>
<asp:ListItem>C</asp:ListItem>
<asp:ListItem>D</asp:ListItem>
<asp:ListItem>E</asp:ListItem>
<asp:ListItem>F</asp:ListItem>
<asp:ListItem>G</asp:ListItem>
<asp:ListItem>H</asp:ListItem>
<asp:ListItem>I</asp:ListItem>
<asp:ListItem>J</asp:ListItem>
<asp:ListItem>K</asp:ListItem>
<asp:ListItem>L</asp:ListItem>
<asp:ListItem>M</asp:ListItem>
<asp:ListItem>N</asp:ListItem>
<asp:ListItem>O</asp:ListItem>
<asp:ListItem>P</asp:ListItem>
<asp:ListItem>Q</asp:ListItem>
<asp:ListItem>R</asp:ListItem>
<asp:ListItem>S</asp:ListItem>
<asp:ListItem>T</asp:ListItem>
<asp:ListItem>U</asp:ListItem>
<asp:ListItem>V</asp:ListItem>
<asp:ListItem>W</asp:ListItem>
<asp:ListItem>X</asp:ListItem>
<asp:ListItem>Y</asp:ListItem>
<asp:ListItem>Z</asp:ListItem>
</asp:DropDownList></td>
<td><asp:CheckBox ID="chbshow1" runat="server" Text="是" /> </td>
<td>添加游戏服务区</td>
<td><asp:LinkButton ID="lkbedit" CommandName="Update" Text="更新" runat="server"></asp:LinkButton>
<asp:LinkButton ID="lkbcancel" CommandName="Cancel" Text="取消" runat="server"></asp:LinkButton></td>
<td><asp:LinkButton ID="lkbdelete" CommandName="Delete" runat="server" Text="删除"></asp:LinkButton></td>
</EditItemTemplate>
</asp:DataList>
<table><tr><td height="5"></td></tr></table>
共<asp:Label id="labcountpage" runat="server"></asp:Label>页
第<asp:Label id="labpage" runat="server"></asp:Label>页
<asp:LinkButton id="lbtnfirstpage" runat="server" onclick="lbtnfirstpage_Click">首页</asp:LinkButton>
<asp:LinkButton id="lbtnpritpage" runat="server" onclick="lbtnpritpage_Click">前一页</asp:LinkButton>
<asp:LinkButton id="lbtnnextpage" runat="server" onclick="lbtnnextpage_Click">下一页</asp:LinkButton>
<asp:LinkButton id="lbtndownpage" runat="server" onclick="lbtndownpage_Click">最后一页</asp:LinkButton>
</td>
</tr>
</tbody>
</table>
cs代码
private void aspnetpagerbind()
{
string str = "select GameClass_ID,GameClass_Name,GameClass_FristName,GameClass_Visible from GameClass order by GameClass_FristName";
if (Request.QueryString["zm"] != null)
str = "select GameClass_ID,GameClass_Name,GameClass_FristName,GameClass_Visible from GameClass where GameClass_FristName='" + this.dd_fristname1.SelectedValue.Trim() + "'";
DataSet ds = help.GetDataSet(str);
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 15;
pds.CurrentPageIndex = Convert.ToInt32(this.labpage.Text) - 1;
list.DataSource = pds;
labcountpage.Text = pds.PageCount.ToString();
labpage.Text = Convert.ToString(pds.CurrentPageIndex + 1);
this.lbtnpritpage.Enabled = true;
this.lbtnfirstpage.Enabled = true;
this.lbtnnextpage.Enabled = true;
this.lbtndownpage.Enabled = true;
if (pds.CurrentPageIndex < 1)
{
this.lbtnpritpage.Enabled = false;
this.lbtnfirstpage.Enabled = false;
}
if (pds.CurrentPageIndex == pds.PageCount - 1)
{
this.lbtnnextpage.Enabled = false;
this.lbtndownpage.Enabled = false;
}
list.DataBind();
}
protected void lbtnpritpage_Click(object sender, System.EventArgs e)
{
this.labpage.Text = Convert.ToString(Convert.ToInt32(labpage.Text) - 1);
this.aspnetpagerbind();
}
protected void lbtnfirstpage_Click(object sender, System.EventArgs e)
{
this.labpage.Text = "1";
this.aspnetpagerbind();
}
protected void lbtnnextpage_Click(object sender, System.EventArgs e)
{
this.labpage.Text = Convert.ToString(Convert.ToInt32(labpage.Text) + 1);
this.aspnetpagerbind();
}
protected void lbtndownpage_Click(object sender, System.EventArgs e)
{
this.labpage.Text = this.labcountpage.Text;
this.aspnetpagerbind();
}
protected void list_CancelCommand(object source, DataListCommandEventArgs e)
{
this.list.EditItemIndex = -1;
aspnetpagerbind();
}
protected void list_DeleteCommand(object source, DataListCommandEventArgs e)
{
string id = list.DataKeys[e.Item.ItemIndex].ToString().Trim();
int k = help.SqlExecute("delete from GameClass where GameClass_ID='" + id + "'");
k = help.SqlExecute("delete from GameServer where GameArea_ID in ( select GameArea_ID from GameArea where GameClass_ID='" + id + "') ");
k = help.SqlExecute("delete from GameArea where GameClass_ID='" + id + "'");
aspnetpagerbind();
}
protected void list_EditCommand(object source, DataListCommandEventArgs e)
{
this.list.EditItemIndex = e.Item.ItemIndex;
aspnetpagerbind();
DropDownList mylist = (DropDownList)list.Items[e.Item.ItemIndex].FindControl("dd_fristname");
Label mylable = (Label)list.Items[e.Item.ItemIndex].FindControl("fristnamehiddle");
mylist.Items.FindByValue(mylable.Text.Trim()).Selected = true;
CheckBox cb = (CheckBox)list.Items[e.Item.ItemIndex].FindControl("chbshow1");
Label labelshow = (Label)list.Items[e.Item.ItemIndex].FindControl("lbshow3");
if (labelshow.Text.Trim() == "1")
cb.Checked = true;
}
protected void list_UpdateCommand(object source, DataListCommandEventArgs e)
{
Label namehiddle_1 = (Label)list.Items[e.Item.ItemIndex].FindControl("namehiddle");
Label id = (Label)list.Items[e.Item.ItemIndex].FindControl("lb_id");
TextBox name = (TextBox)list.Items[e.Item.ItemIndex].FindControl("txtname");
DropDownList zm = (DropDownList)list.Items[e.Item.ItemIndex].FindControl("dd_fristname");
int show = 0;
CheckBox cb1 = (CheckBox)list.Items[e.Item.ItemIndex].FindControl("chbshow1");
if (cb1.Checked)
show = 1;
//int k = help.SqlExecute("update GameClass set GameClass_Name='" + name.Text.Trim() + "',GameClass_FristName='" + zm.SelectedValue.Trim() + "',GameClass_Visible='" + show + "' where GameClass_ID='" + id.Text.Trim()+ "'");
chgadmin.game_update(name.Text.Trim(), zm.SelectedValue.Trim(), show, namehiddle_1.Text.Trim(), int.Parse(id.Text.Trim()));
this.list.EditItemIndex = -1;
aspnetpagerbind();
}
编辑列中的Dropdownlist 也可以在EditCommand 事件中绑定 也可以在HTML中写死(上面例子就是这样),下面给出在EditCommand中绑定Dropdownlist
this.list.EditItemIndex = e.Item.ItemIndex;
aspnetpagerbind();
//下面是绑定dropdownlist
string[,] typelist = new string[,] { { "0", "寄售部" }, { "1", "托管部" }, { "2", "代练部" }, { "3", "售后部" } };
DropDownList mylist = (DropDownList)list.Items[e.Item.ItemIndex].FindControl("ddtype");
for (int i = 0; i < 4; i++)
{
mylist.Items.Add(new ListItem(typelist[i,1].Trim(),typelist[i,0].Trim()));
}
Label mylable = (Label)list.Items[e.Item.ItemIndex].FindControl("typehiddle");
mylist.Items.FindByValue(mylable.Text.Trim()).Selected = true;