解释DataControlRowType只是不了解它. [英] Explain DataControlRowType Just don't understand it.
问题描述
嗨
我已经阅读了所有教程,就像过去12个小时我一直在阅读法语一样,我嵌套了gridview,孩子需要从父母那里获取值我已经走了这么远,请仔细阅读我的代码并将我的位置更正我错了.
Hi
I''ve read all the tutorials Its like I''ve been reading french for the Past 12 hours I have nested gridviews which the child needs to get values from parent I''ve come this far please review my code and correct me where I am wrong.
<asp:GridView ID="GrdJobSht" runat="server" AutoGenerateColumns="False" DataSourceID="GetJobSheetDATA" OnRowDataBound="GrdJobSht_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table><tr><td rowspan="5" class="style4">
<asp:Image ID="ProdImage" runat="server" Height="152px"
ImageUrl='<%# String.Format(ResolveUrl("ProductImage.ashx")+"{0}{1}","?id=",Eval("propImageId")) %>'
style="margin-left: 0px" Width="172px" BorderColor="Silver"
BorderStyle="Double" BorderWidth="10pt" />
</td></tr><tr><td class="style5">
<asp:Label ID="Label1" runat="server" Text="Product ID:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblProdid" runat="server" Text='<%# Eval("propProdId") %>'></asp:Label>
</td></tr><tr><td class="style5">
<asp:Label ID="Label2" runat="server" Text="Description:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("propProdDesc") %>'></asp:Label>
</td></tr><tr><td class="style5">
<asp:Label ID="Label3" runat="server" Text="Quantity:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblQty" runat="server" Text= '<%# Eval("propProdQty") %>'></asp:Label>
</td></tr><tr>
<td class="style5">
<asp:Label ID="Label4" runat="server" Text="Colour:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblColor" runat="server" Text='<%# Eval("propColour") %>'></asp:Label>
</td></tr><tr><td class="style5">
<asp:Label ID="Label5" runat="server" Text="Def Design:" Font-Italic="True"
Font-Names="Times New Roman" Font-Size="Medium"></asp:Label>
</td><td>
<asp:Label ID="lblDefDes" runat="server" Text='<%# Eval("propDeflectionDesign") %>'></asp:Label>
</td></tr></table>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>
Measurements
</HeaderTemplate>
<ItemTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="obsMeas">
<Columns>
<asp:BoundField DataField="propWidth" HeaderText="propWidth" SortExpression="propWidth" />
<asp:BoundField DataField="propHeight" HeaderText="propHeight" SortExpression="propHeight" />
<asp:BoundField DataField="ProprodId" HeaderText="ProprodId" SortExpression="ProprodId" />
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="obsMeas" runat="server" SelectMethod="getProdMeasurements" TypeName="BusinessLogicLayer.Measurements" OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:Parameter Name="qno" Type="Int32" />
<asp:Parameter Name="id" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
这就是我添加参数的方式,但是它以某种方式返回false,我不应该这样,因为如果没有嵌套的Gridview,主数据库将被适当地填充
And this is how I add the parameters but somehow it returns false which shouldn''t be the case I think because without the nested Gridview the master database gets populated appropriately
protected void GrdJobSht_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//returns false hence does not execute code inside
{
SqlDataSource s = (SqlDataSource)e.Row.FindControl("obsMeas");
s.SelectParameters[0].DefaultValue = DDlQno.Text;
s.SelectParameters[1].DefaultValue = ((Label)e.Row.FindControl("lblProdid")).Text;
}
}
推荐答案
首先,您做错了.
1st of all , you are doing it wrong .
<asp:objectdatasource id="obsMeas" runat="server" selectmethod="getProdMeasurements" xmlns:asp="#unknown">
</asp:objectdatasource>
此"obsMeas"控件位于网格视图的外部,您正在尝试通过((SqlDataSource)e.Row.FindControl("obsMeas");"进行访问.在GridView的数据边界中,我认为这是不可能的.
看看这个代码示例,
This "obsMeas" Control is present out side the grid view, and you are trying to access it by "(SqlDataSource)e.Row.FindControl("obsMeas");" in side GridView''sData Bound, which I think is not possible.
Have a look at this Code Sample,
<asp:templatefield headertext="HeaderText">
<itemtemplate>
<asp:label id="lbl" runat="server"></asp:label>
</itemtemplate>
</asp:templatefield>
//--CodeBehind
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow dr = ((DataRowView)e.Row.DataItem).Row;
if(dr["ColumnName"].ToString() == "1" )
{
((Label)e.Row.FindControl("lbl")).Text = "A";
}
else if(dr["ColumnName"].ToString() == "2" )
{
((Label)e.Row.FindControl("lbl")).Text = "B";
}
................
................
}
}
通过此MSDN链接获取 GridView.RowDataBound事件
Go through this MSDN link for GridView.RowDataBound Event
这篇关于解释DataControlRowType只是不了解它.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!