如何从嵌套在转发器中的datagrid中检索值。 [英] How to retrieve value from datagrid nested in repeater.

查看:56
本文介绍了如何从嵌套在转发器中的datagrid中检索值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助获取所选行中单元格的值。我得到空字符串。非常感谢!!!

1. asp页面代码:

< asp:Repeater ID =Repeater1runat =serverDataMember =typeOnItemDataBound =getNestedData>

< itemtemplate>





<%#Container .DataItem(type)%>















< asp:Gridview ID =GridView1runat =serverAutoGenerateColumns =FalseWidth =445pxDataKeyField =familyidAllowPaging =True

ShowHeader =TrueHeaderStyle-CssClass =MenuBarHorizo​​ntal

OnRowCommand =GridView1_RowCommand

SelectedRowStyle-Horizo​​ntalAlign =left

AlternatingRowStyle-Horizo​​ntalAlign =left>

< columns>

< asp:ButtonField HeaderText =MII Part No. DataTextField =family_no

SortExpression =familyidControlStyle-Width =20ItemStyle-Width =130

CommandName =select/>

< asp:ButtonField HeaderText =部分描述

DataTextField =descrSortExpression =descr

CommandName =select />

< asp:BoundField HeaderText =家庭ID

DataField =familyidSortExpression =familyidVisible =False/>













2.在asp页面上填充视图后面的代码

受保护的子页面_Load(发送者作为对象,e As处理Me.Load

如果不是IsPostBack那么

Dim ds作为新数据集

Dim sMyTable As String =ProductType

Dim sSql As String =SELECT typeid,categid,image,type FROM(product_type)ORDER BY type

ds = GetMyDataset(sMyTable,sSql)

如果ds.Tables(0).Rows.Count> 0然后

Dim dv作为新DataView(ds.Tables(0))

Repeater1.DataSource = dv

Repeater1.DataBind()

结束如果

ds.Clear()

ds.Dispose()

结束如果

End Sub

Sub getNestedData(ByVal Sender As Object,ByVal e As RepeaterItemEventArgs)

Dim ds As New DataSet

Dim ad As DataTable

Dim sMyTable As String =ProductFamily

Dim subGridView As GridView

subGridView = e.Item.FindControl(GridView1)

Dim key As String = e.Item.DataItem(type)

Dim sSql As String =SELECT product_family.family_no,product_family.descr,product_family.familyid FROM product_type INNER JOIN& _

product_family ON product_type.typeid = product_family.typeid where type =''&关键& ''

ds = GetMyDataset(sMyTable,sSql)

如果ds.Tables(0).Rows.Count> 0然后

ad = ds.Tables(0)

subGridView.DataSource = ad

''subGridView.Rows(0).Cells( 0).Text = ad.Rows(0)(family_no)。ToString

''subGridView.Rows(0).Cells(1).Text = ad.Rows(0)( descr)。ToString

''subGridView.Rows(0).Cells(2).Text = ad.Rows(0)(familyid)。ToString

subGridView.DataBind()

结束如果

ds.Clear()

ds.Dispose()

结束Sub

受保护的函数GetImage(ByVal iTypeid As Integer)As String

Dim myImage As String =

Dim ds As New DataSet

Dim ad As DataTable

Dim sMyTable As String =ProductType

Dim sSql As String =SELECT image FROM product_type where typeid ='' &安培; iTypeid& ''

ds = GetMyDataset(sMyTable,sSql)

如果ds.Tables(0).Rows.Count> 0然后

ad = ds.Tables(0)

myImage = ad.Rows(0)(0)

结束如果

ds.Clear()

ds.Dispose()

返回myImage

结束功能



3.获得价值的代码:



受保护的子GridView1_RowCommand(ByVal发送者为对象,ByVal e As System.Web.UI。 WebControls.GridViewCommandEventArgs)

Dim myGridview = DirectCast(发送者,GridView)

如果e.CommandName =select则

Dim index As Integer = Convert.ToInt32(e.CommandArgument)

Dim Id As Integer = myGridView.DataKeys(index).Value()

Dim selectedRow As GridViewRow = myGridview.Rows(index )

Dim name As String = selectedRow.Cells(2).Text

结束如果

Session(myFamilyID)= name



Response.Redirect(sensorlist.aspx)

结束Sub

解决方案

首先,请使用CODE选项在您的问题/答案中附加代码示例。它会自动格式化。这里很难理解你的代码。谢谢


请提供您已经使用过的以下函数的定义



GetMyDataset()

Please help to get the cell''s value in the selected row. I got empty string. Thank you very much!!!
1. asp page code:
<asp:Repeater ID="Repeater1" runat="server" DataMember="type" OnItemDataBound="getNestedData" >
<itemtemplate>


<%#Container.DataItem("type")%>









<asp:Gridview ID="GridView1" runat="server" AutoGenerateColumns="False" Width="445px" DataKeyField="familyid" AllowPaging="True"
ShowHeader="True" HeaderStyle-CssClass="MenuBarHorizontal"
OnRowCommand="GridView1_RowCommand"
SelectedRowStyle-HorizontalAlign="left"
AlternatingRowStyle-HorizontalAlign="left" >
<columns>
<asp:ButtonField HeaderText="MII Part No." DataTextField="family_no"
SortExpression="familyid" ControlStyle-Width="20" ItemStyle-Width="130"
CommandName="select" />
<asp:ButtonField HeaderText="Part Description"
DataTextField="descr" SortExpression="descr"
CommandName="select" />
<asp:BoundField HeaderText="Family ID"
DataField="familyid" SortExpression="familyid" Visible="False" />






2. Code behind to populate view on asp page
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim ds As New DataSet
Dim sMyTable As String = "ProductType"
Dim sSql As String = "SELECT typeid,categid,image, type FROM (product_type) ORDER BY type"
ds = GetMyDataset(sMyTable, sSql)
If ds.Tables(0).Rows.Count > 0 Then
Dim dv As New DataView(ds.Tables(0))
Repeater1.DataSource = dv
Repeater1.DataBind()
End If
ds.Clear()
ds.Dispose()
End If
End Sub
Sub getNestedData(ByVal Sender As Object, ByVal e As RepeaterItemEventArgs)
Dim ds As New DataSet
Dim ad As DataTable
Dim sMyTable As String = "ProductFamily"
Dim subGridView As GridView
subGridView = e.Item.FindControl("GridView1")
Dim key As String = e.Item.DataItem("type")
Dim sSql As String = "SELECT product_family.family_no, product_family.descr,product_family.familyid FROM product_type INNER JOIN " & _
"product_family ON product_type.typeid = product_family.typeid where type=''" & key & "''"
ds = GetMyDataset(sMyTable, sSql)
If ds.Tables(0).Rows.Count > 0 Then
ad = ds.Tables(0)
subGridView.DataSource = ad
''subGridView.Rows(0).Cells(0).Text = ad.Rows(0)("family_no").ToString
''subGridView.Rows(0).Cells(1).Text = ad.Rows(0)("descr").ToString
''subGridView.Rows(0).Cells(2).Text = ad.Rows(0)("familyid").ToString
subGridView.DataBind()
End If
ds.Clear()
ds.Dispose()
End Sub
Protected Function GetImage(ByVal iTypeid As Integer) As String
Dim myImage As String = ""
Dim ds As New DataSet
Dim ad As DataTable
Dim sMyTable As String = "ProductType"
Dim sSql As String = "SELECT image FROM product_type where typeid=''" & iTypeid & "''"
ds = GetMyDataset(sMyTable, sSql)
If ds.Tables(0).Rows.Count > 0 Then
ad = ds.Tables(0)
myImage = ad.Rows(0)(0)
End If
ds.Clear()
ds.Dispose()
Return myImage
End Function

3. Code to get value:

Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)
Dim myGridview = DirectCast(sender, GridView)
If e.CommandName = "select" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim Id As Integer = myGridView.DataKeys(index).Value()
Dim selectedRow As GridViewRow = myGridview.Rows(index)
Dim name As String = selectedRow.Cells(2).Text
End If
Session("myFamilyID") = name

Response.Redirect("sensorlist.aspx")
End Sub

解决方案

First of all, Kindly use CODE option in order to attach code sample in your question/answer. It will format it automatically. It is very difficult to understand your code here. Thanks


please provide the definition of the following function which you have used in number of times

GetMyDataset()


这篇关于如何从嵌套在转发器中的datagrid中检索值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆