这是原帖:原帖首先谢谢大家的热情! 但是 我很无奈
难道我描述问题不够清楚吗? 我现在想实现的效果是 当我点击编辑之后 类型那一列呈现的不是textbox 而是一个下拉菜单 例如DropDownList 对于GV的列<asp:BoundField HeaderText="类型" />正常情况是这样的: 当其处于非编辑状态时 它的呈现样式是一个table的cell样式 当处于编辑状态时,它的呈现样式是cell里面放一个TextBox 这样就可以编辑里面的内容 我要的样式是 当处于编辑状态时,它的呈现样式是cell里面放一个Dropdownlist 当非编辑状态时 它的呈现样式就是普通的BoundField 回答者告诉我的答案几乎全是非编辑状态 呈现出Dropdownlist 这个根本不难 而且MSDN也有示例 但我不是要的这种请大家看清楚描述再帮我解答 谢谢
难道我描述问题不够清楚吗? 我现在想实现的效果是 当我点击编辑之后 类型那一列呈现的不是textbox 而是一个下拉菜单 例如DropDownList 对于GV的列<asp:BoundField HeaderText="类型" />正常情况是这样的: 当其处于非编辑状态时 它的呈现样式是一个table的cell样式 当处于编辑状态时,它的呈现样式是cell里面放一个TextBox 这样就可以编辑里面的内容 我要的样式是 当处于编辑状态时,它的呈现样式是cell里面放一个Dropdownlist 当非编辑状态时 它的呈现样式就是普通的BoundField 回答者告诉我的答案几乎全是非编辑状态 呈现出Dropdownlist 这个根本不难 而且MSDN也有示例 但我不是要的这种请大家看清楚描述再帮我解答 谢谢
解决方案 »
- a标签加上runat属性后出现的问题
- 菜鸟的几个问题,谢谢各位帮助
- 如何换行?在线等
- AJAX问题,,AJAX会导致页面aborted吗?
- 一个关于DataGrid嵌套DataGrid的问题..?
- “常规网络错误。请检查您的网络文档。”,这是什么回事
- 请问有人用过FCKeditor吗?我从网站上下了一个FCKeditor.Net_2.1.zip,可不会用?(急!)
- 有什么办法可以从表里获取约束关系字段呢?
- 在win2000 server上运行aspx,报错"Server Application Unavailable",有人碰到过吗?
- VS.net无法新建或打开任何项目!!为什么!!
- UpdatePanel能放在table里面吗
- 3层构架刚开始怎么做???新手!
2.在GridView里添加三个事件OnRowEditing,OnRowCancelingEdit,OnRowUpdating
再在事件上写上相应的代码代码片段:
ASPX文件:
<asp:GridView ID="gvRequestRoleList" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" AllowPaging="True" OnPageIndexChanging="gvRequestRoleList_PageIndexChanging"
OnRowEditing="gvRequestRoleList_RowEditing" OnRowCancelingEdit="gvRequestRoleList_RowCancelingEdit"
OnRowUpdating="gvRequestRoleList_RowUpdating">
.......
<asp:TemplateField HeaderText="申请权限">
<EditItemTemplate>
<asp:DropDownList ID="ddlRequestRole" runat="server">
<asp:ListItem Value="Common">普通用户</asp:ListItem>
<asp:ListItem Value="Intermediate">中级用户</asp:ListItem>
<asp:ListItem Value="Senior">高级用户</asp:ListItem>
<asp:ListItem Value="Admin">超级用户</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("RequestRoleCHName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
.......
</asp:GridView>CS文件:
//用户按"修改权限"(更新)时
protected void gvRequestRoleList_RowEditing(object sender, GridViewEditEventArgs e)
{
gvRequestRoleList.EditIndex = e.NewEditIndex;
//绑定数据
RequestRoleListDataBind();
}//用户取消操作时
protected void gvRequestRoleList_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvRequestRoleList.EditIndex = -1;
//绑定数据
RequestRoleListDataBind();
}//更新操作
protected void gvRequestRoleList_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
//获得DropDownList 控件
DropDownList ddlRequestRole = gvRequestRoleList.Rows[e.RowIndex].Cells[5].FindControl("ddlRequestRole") as DropDownList;
string roleName = ddlRequestRole.SelectedItem.Value;
Label lblUserName = gvRequestRoleList.Rows[e.RowIndex].Cells[2].FindControl("lblUserName") as Label;
string userName = lblUserName.Text; //更新用户的角色
ChangeRole(userName, roleName);
//审核用户的申请
//....(略) //刷新页面
//....(略) }
这个就是你要想要的想过嘛
<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("绑定的字段")%>'> </asp:Label> 编辑模板下的那个dropdownList 可以两种办法绑定第1是选中gridview点编辑模板,然后选中编辑模板,你会看到你的dropdownlist,然后拖入sqldatasource进行绑定或者在gridView进入编辑状态下的时候,动态在事件下用 findControl找到dropdownlist进行手动绑定
//参考:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound" Width="590px" >
<Columns>
<asp:TemplateField HeaderText="类别">
<ItemTemplate>
<%# Eval("类别字段") %>
</ItemTemplate>
<EditItemTemplate>
<asp:Label runat="server" id="sp" Text='<%#Eval("类别字段") %>' Visible=false/>
<asp:DropDownList ID="ddlInfo" runat="server">
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns>
</asp:GridView>//后台事件:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果为编辑情况下时,绑定下拉框控件。
DropDownList ddlinfo = (DropDownList)e.Row.FindControl("ddlInfo");
if (ddlinfo != null)
{
ddlinfo.DataSource = bsi.SelectAll(); //指定下拉框数据源
ddlinfo.DataTextField = "类别名";
ddlinfo.DataValueField = "类别id";
ddlinfo.DataBind();
//选定为默认值
ddlinfo.SelectedValue = ((Label)e.Row.FindControl("sp")).Text;
}
}
http://www.componentart.com/webui/demos/demos_control-specific/grid/editing/editing_dataCallbackMode/WebForm1.aspx