<asp:GridView ID="DtgView" runat="server" AutoGenerateColumns="False" Width="98%" Height=98%
BorderStyle="None" GridLines="Horizontal" frame="void" AllowPaging="True" EnableViewState="false"
OnRowDataBound="DtgView_RowDataBound">
<Columns>
<asp:BoundField DataField="EquiId" HeaderText="EquiId" Visible=false />
<asp:TemplateField HeaderText="设备名称">
<ItemTemplate>
<%#GetEquipName(DataBinder.Eval(Container.DataItem, "EquiId").ToString())%>
</ItemTemplate>
<ItemStyle Width="30%" />
</asp:TemplateField >
<asp:TemplateField HeaderText="确认状态">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
</ItemTemplate>
<ItemStyle Width="10%" />
</asp:TemplateField >
<tr>
<td align=center>
<asp:Button runat="server" ID="btn_save" Text="保 存" CssClass="NewButton" CausesValidation="false" OnClick="btn_save_Click" />
<asp:Button runat="server" ID="btn_submit" Text="确 定" CssClass="NewButton" CausesValidation="false" OnClick="btn_submit_Click" />
</td>
</tr>
服务器:
protected void DtgView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("DropDownList1");
ddl.DataSource = task.GetConfirmStatus();
ddl.DataTextField = "StatusName";
ddl.DataValueField = "id";
ddl.DataBind();
ListItem li = new ListItem("请选择", "0");
ddl.Items.Insert(0, li);
}
}
protected void btn_save_Click(object sender, EventArgs e)
{
//这块怎么写????急!
}
我需要点击“确定键”,将所有的dropdownlist里的值和对应的行的equiid保存到数据库中。不知道该用gridview中的哪个事件能做到,谁能教教我?多谢!
6 个解决方案
#1
<asp:DropDownList ID="ddlProductType" runat="server">
</asp:DropDownList>
<asp:HiddenField ID="HidTypeID" Value='<%# Eval("主键Id") %>' runat="server" />
后台循环遍历每一行 得到数据
</asp:DropDownList>
<asp:HiddenField ID="HidTypeID" Value='<%# Eval("主键Id") %>' runat="server" />
后台循环遍历每一行 得到数据
#2
i=0;i<Gridview1.Rows.count;i++
GridView1.rows[i].cells[2]
GridView1.rows[i].cells[2]
#3
我先试一试。多谢ls两位。关键是后台遍历是用gridview的事件还是自己写循环?
#4
不行啊,得到的是这些:
System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell
System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell
#5
#6
可以了!
这么写就可以了:
protected void btn_save_Click(object sender, EventArgs e)
{
string var = "";
for (int i = 0; i < DtgView.Rows.Count; i++)
{
var = var + "; " + ((DropDownList)DtgView.Rows[i].Cells[2].FindControl("DropDownList1")).SelectedValue;
}
Response.Write(var);
}
结果为:; 1; 2; 0; 0; 0; 0; 0; 0; 0; 0
多谢!
这么写就可以了:
protected void btn_save_Click(object sender, EventArgs e)
{
string var = "";
for (int i = 0; i < DtgView.Rows.Count; i++)
{
var = var + "; " + ((DropDownList)DtgView.Rows[i].Cells[2].FindControl("DropDownList1")).SelectedValue;
}
Response.Write(var);
}
结果为:; 1; 2; 0; 0; 0; 0; 0; 0; 0; 0
多谢!
#1
<asp:DropDownList ID="ddlProductType" runat="server">
</asp:DropDownList>
<asp:HiddenField ID="HidTypeID" Value='<%# Eval("主键Id") %>' runat="server" />
后台循环遍历每一行 得到数据
</asp:DropDownList>
<asp:HiddenField ID="HidTypeID" Value='<%# Eval("主键Id") %>' runat="server" />
后台循环遍历每一行 得到数据
#2
i=0;i<Gridview1.Rows.count;i++
GridView1.rows[i].cells[2]
GridView1.rows[i].cells[2]
#3
我先试一试。多谢ls两位。关键是后台遍历是用gridview的事件还是自己写循环?
#4
不行啊,得到的是这些:
System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell
System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell; System.Web.UI.WebControls.DataControlFieldCell
#5
#6
可以了!
这么写就可以了:
protected void btn_save_Click(object sender, EventArgs e)
{
string var = "";
for (int i = 0; i < DtgView.Rows.Count; i++)
{
var = var + "; " + ((DropDownList)DtgView.Rows[i].Cells[2].FindControl("DropDownList1")).SelectedValue;
}
Response.Write(var);
}
结果为:; 1; 2; 0; 0; 0; 0; 0; 0; 0; 0
多谢!
这么写就可以了:
protected void btn_save_Click(object sender, EventArgs e)
{
string var = "";
for (int i = 0; i < DtgView.Rows.Count; i++)
{
var = var + "; " + ((DropDownList)DtgView.Rows[i].Cells[2].FindControl("DropDownList1")).SelectedValue;
}
Response.Write(var);
}
结果为:; 1; 2; 0; 0; 0; 0; 0; 0; 0; 0
多谢!