62,268
社区成员
发帖
与我相关
我的任务
分享
<asp:TemplateField HeaderText="审核状态">
<ItemTemplate>
<asp:Label ID="lblaudit" runat="server" Text='<%# Eval("F_Audit") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButtonList ID="AuditRBL" runat="server" RepeatDirection="Vertical" AutoPostBack="true" AppendDataBoundItems="true">
<asp:ListItem Value="0" Text="未通过"></asp:ListItem>
<asp:ListItem Value="1" Text="已通过"></asp:ListItem>
</asp:RadioButtonList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="级别">
<ItemTemplate>
<asp:Label ID="lbllevel" runat="server" Text='<%# Eval("F_Level") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:RadioButtonList ID="LevelRBL" runat="server" RepeatDirection="Horizontal" AutoPostBack="true" AppendDataBoundItems="true">
<asp:ListItem Value="0" Text="普通会员"></asp:ListItem>
<asp:ListItem Value="1" Text="ViP"></asp:ListItem>
</asp:RadioButtonList>
</EditItemTemplate>
</asp:TemplateField>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
pagebind();
}
}
private void pagebind()
{
string str = "SELECT * FROM T_Member";
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(str, olecon);
da.Fill(ds,"T_Member");
rowCount = ds.Tables["T_Member"].Rows.Count;
GridView1.DataSource = ds;
GridView1.DataKeyNames = new string[]{"Member_ID"};
GridView1.DataBind();
olecon.Close();
}
protected void GridView_RowDataBound(object sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
numCount++;
if (e.Row.RowIndex == GridView1.EditIndex)
{
DataRowView rowItem = (DataRowView)e.Row.DataItem;
if (rowItem["Member_ID"] != DBNull.Value)
{
RadioButtonList auditrbl = (RadioButtonList)e.Row.FindControl("AuditRBL");
auditrbl.SelectedIndex = (Convert.ToInt32(rowItem["F_Audit"]));
}
if (rowItem["Member_ID"] != DBNull.Value)
{
RadioButtonList levelrbl = (RadioButtonList)e.Row.FindControl("LevelRBL");
levelrbl.SelectedIndex = (Convert.ToInt32(rowItem["F_Level"]));
}
}
}
if (e.Row.RowType == DataControlRowType.Footer)
{
int toLeft = TotalRowCount - numCount;
int numCols = GridView1.Rows[0].Cells.Count;
for (int i = 0; i < toLeft; i++)
{
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
for (int j = 0; j < numCols; j++)
{
TableCell cell = new TableCell();
cell.Text = " ";
row.Cells.Add(cell);
}
GridView1.Controls[0].Controls.AddAt(numCount + 1 + i, row);
}
}
}
protected void RowEditing(object sender,GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
pagebind();
}
protected void GridView_RowCommand(object sender,GridViewCommandEventArgs e)
{
RadioButtonList auditrbl = (RadioButtonList)GridView1.FindControl("AuditRBL");
RadioButtonList levelrbl = (RadioButtonList)GridView1.FindControl("LevelRBL");
if (e.CommandName == "update")
{
string id = e.CommandArgument.ToString();
string audit = auditrbl.SelectedItem.Value.ToString();
string level = levelrbl.SelectedItem.Value.ToString();
string str = "UPDATE T_Member SET [F_Audit]=" + audit + ",[F_Level]=" + level + ";";
olecmd = new OleDbCommand(str, olecon);
olecon.Open();
olecmd.ExecuteNonQuery();
olecon.Close();
}
}
foreach (GridViewRow grow in GridView1.Rows)
{
RadioButtonList auditrbl = (RadioButtonList)(grow .FindControl("AuditRBL"));
}