读书人

GridView选中行获取ID有关问题

发布时间: 2012-01-24 23:11:54 作者: rapoo

GridView选中行获取ID问题
<asp:GridView ID= "gvSelPatient " runat= "server " AllowSorting= "false " AutoGenerateColumns= "false "
DataKeyNames= "PatientID " HeaderStyle-Wrap= "true " OnRowDataBound= "gvSelPatient_RowDataBound "
Width= "100% " OnRowCommand= "gvSelPatient_RowCommand ">
<Columns>
<asp:TemplateField HeaderText= "选择 " ItemStyle-Width= "7% ">
<ItemTemplate>
<%-- <a id= "lbSelect " href= "# " onclick= "choice() "> 选择 </a> --%>
<%-- <a id= "lkSelect " href= "# " onclick= "setPatientInfo() "> 选择 </a> --%>
<input name= "mycheck " onclick= "choice(this) " type= "checkbox " value= "选择 " />
<%-- <input onclick= "white(this) " type= "radio " value= "选择 " /> --%>


</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField= "PatientID " HeaderText= "PatientID " ReadOnly= "True " SortExpression= "PatientID " Visible= "false ">
<ItemStyle CssClass= "hidden " />
<HeaderStyle CssClass= "hidden " />
<FooterStyle CssClass= "hidden " />
</asp:BoundField>
<asp:BoundField DataField= "PatientName " HeaderText= "姓名 " ItemStyle-Width= "10% " />
<asp:BoundField DataField= "Sex " HeaderText= "性别 " ItemStyle-Width= "7% " />
<asp:BoundField DataField= "Birthday " DataFormatString= "{0:d} " HeaderText= "出生年月 " HtmlEncode= "False "


ItemStyle-Width= "10% " />
<asp:BoundField DataField= "Telephone " HeaderText= "联系电话 " ItemStyle-Width= "10% " />
<asp:BoundField DataField= "Address " HeaderText= "地址 " ItemStyle-Width= "10% " />
<asp:BoundField DataField= "Job " HeaderText= "职业 " ItemStyle-Width= "10% " />
<asp:TemplateField HeaderText= "是否保险 " ItemStyle-Width= "10% ">
<ItemTemplate>
<asp:Label ID= "Label1 " runat= "server " Text= ' <%# Convert.ToBoolean(Eval( "DoesInsurance "))? "是 ": "否 " %> '> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField= "Insurance " HeaderText= "保险类别 " ItemStyle-Width= "10% " />


<asp:BoundField DataField= "InsuranceNumber " HeaderText= "保险号 " ItemStyle-Width= "8% " />
</Columns>
<EmptyDataTemplate>
<table width= "100% ">
<tr>
<td>
姓名 </td>
<td>
性别 </td>
<td>
出生年月 </td>


<td>
联系电话 </td>
<td>
地址 </td>
<td>
职业 </td>
<td>
是否保险 </td>
</tr>
</table>
</EmptyDataTemplate>


</asp:GridView>

在后台C#中如何获取PatientID

[解决办法]
以下是DataGrid的例子

改一下即可

private void DataGrid1_ItemDataBound(object sender,System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataRowView drv = e.Item.DataItem as DataRowView;
int iProjectID = Convert.ToInt32(drv[ "ProjectID "].ToString());
}
[解决办法]
gridview.datakeys[itemindex]
[解决办法]
用脚本的话.可以把GridView 看成一个table。
[解决办法]
gridview.datakeys[itemindex]

这样写还可以吗?

=========

脚本取不倒存到 DataKeys 的值,通过隐藏列 或者 隐藏控件

读书人网 >asp.net

热点推荐