this.GridView1.FindControl("ControlID");或者通过JQuery查看客户端id在前台获得值。
解决方案 »
- treeview控件进度条
- 与“string.Split(params char[])”最匹配的重载方法具有一些无效参数
- ===========各位大大如何在打包程序中添加一个Dialog来配置Web.config文件==========
- 为什么一按shift就.net2003就自动关了
- ewebeditor的奇怪问题,实在搞不定了,那位兄弟帮帮忙
- DATAGRID中提供删除按钮,怎样让其在点击删除前响应确定。
- 帮我推荐一家便宜,信用好,服务好的提供域名,空间的地方吧。
- 如何获得控件
- 急啊,快帮忙解决啊:下面哪里出问题了?
- 我写了一个共用函数,用于生成一个EXCEL,并下载到客户端,怎么让各个页面都能向这个函数传递参数呢?
- asp.net ffmpeg获取视频宽高
- [请教RSS高手]RSS如何获取早期的订阅内容
OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting" DataKeyNames="id">
<Columns>
<asp:TemplateField HeaderText="序号" SortExpression="Id">
<ItemTemplate>
<%# (this.AspNetPager1.CurrentPageIndex - 1) * this.AspNetPager1.PageSize + Container.DataItemIndex + 1%>
</ItemTemplate>
<ItemStyle Wrap="True" />
<HeaderStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
学号</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblxh" runat="server" Text='<%#Eval("StuNo") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="StuName" HeaderText="姓名" SortExpression="StuName" />
<asp:BoundField HeaderText="课程名称" SortExpression="Gender" DataField="LessonName" />
<asp:BoundField DataField="ClassName" HeaderText="班级名称" SortExpression="ClassName" />
<asp:BoundField HeaderText="录入次数" />
<asp:TemplateField HeaderText="成绩类型"></asp:TemplateField>
<asp:TemplateField HeaderText="考核成绩">
<ItemTemplate>
<asp:DataList ID="dtlist1" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dtlist1_ItemDataBound">
<ItemTemplate>
<table border="0" cellspacing="0" cellpadding="0" width="99%"">
<tbody>
<tr>
<td>
<asp:Label ID="lblxm" runat="server" Text='<%#Eval("Contents") %>'></asp:Label>
</td>
</tr>
<tr>
<td valign="top" align="left">
<asp:TextBox ID="txtboxfenshu" runat="server" Width="50px"></asp:TextBox>
</td>
</tr>
</tbody>
</table>
</ItemTemplate>
</asp:DataList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>后台cs
protected void dtlist1_ItemDataBound(object sender, DataListItemEventArgs e)
{
string whicht = "";
string whichid = "";
string xuehao = ((Label)this.GridView1.FindControl("lblxh")).Text;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string totalid = "txtboxfenshu";
((TextBox)e.Item.FindControl("txtboxfenshu")).Visible = true;
whicht = ((TextBox)e.Item.FindControl("txtboxfenshu")).ClientID.ToString();
whichid = "txtboxfenshu";
((TextBox)e.Item.FindControl("txtboxfenshu")).Attributes.Add("onfocusout", "WriteData('" + e.Item.ItemIndex + "','" + whicht + "','" + whichid + "','" + totalid + "',this)");
}
}但是这么写这一句会报错, string xuehao = ((Label)this.GridView1.FindControl("lblxh")).Text; 提示未将对象引用设置到对象的实例。说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误:
行 494: string whicht = "";
行 495: string whichid = "";
行 496: string xuehao = ((Label)this.GridView1.FindControl("lblxh")).Text;
行 497: if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
行 498: {
目测应该一级一级的获取
((Label)this.GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
显示内层记录中的sql,就包含了外层记录的主键或是你想要的字段记录。