62,264
社区成员
发帖
与我相关
我的任务
分享
<asp:GridView runat="server" id="gv" DataKeyNames="CustomerID"
AutoGenerateColumns="False" onrowdatabound="gv_RowDataBound"
onrowcancelingedit="gv_RowCancelingEdit" onrowdeleting="gv_RowDeleting"
onrowediting="gv_RowEditing" onrowupdating="gv_RowUpdating">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="CustomerID"
DataNavigateUrlFormatString="./CustomerDetails.aspx?CustomerID={0}"
DataTextField="CustomerID" HeaderText="客户编号" />
<asp:BoundField DataField="CompanyName" HeaderText="客户名称" ReadOnly="True"
SortExpression="CompanyName" />
<asp:BoundField DataField="ContactName" HeaderText="联系人"
SortExpression="ContactName" />
<asp:BoundField DataField="ContactTitle" HeaderText="联系主题"
SortExpression="ContactTitle"/>
<asp:TemplateField HeaderText="城市">
<ItemTemplate>
<asp:DropDownList runat="server" ID="cityDpt"></asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowEditButton="True" />
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
</Columns>
</asp:GridView>
protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string customerId = ((HyperLink)gv.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
string companyName = gv.Rows[e.RowIndex].Cells[1].Text;
string contactName = gv.Rows[e.RowIndex].Cells[2].Text;
string contactTitle = gv.Rows[e.RowIndex].Cells[3].Text;
string city = (gv.Rows[e.RowIndex].FindControl("cityDpt") as DropDownList).SelectedItem.Text;
}