gridview单元格中获取行索引。。。

在gridview中放入个dropdownlist 然后我想实现 点击  

dropdownlist 的selectindexchange 事件中获取   

gridview的行索引 

 

 

如图 

 HTML前台代码 

  <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="false" 
CellPadding="3" CellSpacing="1" CssClass="dataTableStyle" DataKeyNames="zcbm"
ForeColor="#333333" GridLines="None" OnRowDataBound="GridView3_RowDataBound"
PageSize="20">
<Columns>

<asp:BoundField DataField="FHSL" HeaderText="符合数量" />
<asp:BoundField DataField="BZ" HeaderText="备注" />
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem>请选择</asp:ListItem>
<asp:ListItem>借出</asp:ListItem>
<asp:ListItem>租出</asp:ListItem>
<asp:ListItem>毁损</asp:ListItem>
<asp:ListItem>盘亏</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
<asp:Label ID="Label21" runat="server" Text="盘点未见原因"></asp:Label>
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<PagerSettings Visible="False" />
<RowStyle BackColor="white" HorizontalAlign="Left" />
<FooterStyle BackColor="#7799CC" Font-Bold="True" ForeColor="White" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" Font-Size="Large"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>

后台获取行索引:

 protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{

int i;
var dropDown = sender as DropDownList;
TableCell cell = null;
if (dropDown != null)
{
cell = dropDown.Parent as TableCell;
var row = cell.Parent as GridViewRow;
i = row.RowIndex;
string guid = GridView3.Rows[i].Cells[1].Text;//获取当前行的guid
if (dropDown.SelectedValue == "借出")
{
Response.Write(" <script language=javascript> window.open ( 'jc.aspx?guid=" + guid + "&dw=" + dw + " ', '借出信息表', 'height=320, width=700, top=200,left=270, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no ') </script> ");

}


}


}



 

posted on 2012-03-30 14:53  小东北  阅读(730)  评论(0编辑  收藏  举报