我在模版列中添加了下拉框和文本框以及一个按钮,希望通过单击按钮可以修改下拉框和文本框中的内容,从而能够修改当前绑定的数据
我通过按钮中的CommandArgument=<%# Eval("Id")%>获得当前行的ID,可是我该如何获得当前文本框和下拉框中的值呢?
真的让我很头痛,请给我详细代码,好么?万分感谢!!!
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="font-size: 13px">
<tr>
<td style="width: 100px"><%# Eval("ProId")%></td>
<td style="width: 100px"><%# Eval("ProName")%></td>
<td style="width: 100px">
<asp:DropDownList ID="DropDownList1" runat="server" Width="100px">
<asp:ListItem>上海</asp:ListItem>
<asp:ListItem>常州</asp:ListItem>
<asp:ListItem>杭州</asp:ListItem>
<asp:ListItem>南京</asp:ListItem>
<asp:ListItem>宁波</asp:ListItem>
<asp:ListItem>温州</asp:ListItem>
<asp:ListItem>无锡</asp:ListItem>
</asp:DropDownList></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox1" runat="server" Width="60px" Text=<%# Eval("ProPrice")%>></asp:TextBox></td>
<td style="width: 100px">
<asp:TextBox ID="TextBox2" runat="server" Width="60px" Text=<%# Eval("ProNumber")%>></asp:TextBox></td>
<td style="width: 100px">
<asp:LinkButton ID="lkbtnEdit" runat="server" OnClick="lkbtnEdit_Click" CommandArgument=<%# Eval("Id")%>>修改</asp:LinkButton>
<asp:LinkButton ID="lkbtnDel" runat="server"  CommandArgument=<%# Eval("Id")%>>删除</asp:LinkButton></td>
</tr>
</table>
</ItemTemplate>
<HeaderTemplate>
<table border="0" cellpadding="0" cellspacing="0" style="font-weight: bold; font-size: 13px;width: 100%">
<tr>
<td style="height: 15px">产品编号</td>
<td style="height: 15px">产品名称</td>
<td style="height: 15px">所在地区</td>
<td style="height: 15px">产品价格</td>
<td style="height: 15px">产品数量</td>
<td style="height: 15px">订单编辑</td>
</tr>
</table>
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>

解决方案 »

  1.   

    加个EditFidleTemplate,这个才是在EDIT状态下显示的
      

  2.   

    获得他们的值也很简单,你的button,CommandArgument= <%# Eval("Id")% >
    在rowdatabound事件里你把commandarguments的值改成“id,rowindex”,就是id和这一行的索引,只要有这一行的索引就能找到下拉框和文本框的值了
      

  3.   


    在编辑事件里写
    ((TextBox)gridview1.Rows[e.editindex].cell[控件所在单元格].findcontrl("文本控件名字")).Text;
    ((DropDownList)gridview1.Rows[e.editindex].cell[控件所在单元格].findcontrl("文本控件名字")).SelectedValue;