当前位置:编程学习 > C#/ASP.NET >>

关于DATALIST传值问题 100分,在线等

 DATALIST2 是嵌套在DATALIST1里面的,用的ObjectDataSource 数据原控件,我DATALIST2的ObjectDataSource 要得到DATALIST1 里面的ID 获取方法是Control 是DATALIST1 的SelectedValue 但得不到DATALIST1里面的ID 也设了dataKey 为ID就是得不到,数据原控件得不到这个值吗?各位大侠帮忙啊 --------------------编程问答-------------------- 顶,帮忙啊,大哥们 --------------------编程问答-------------------- 1 --------------------编程问答--------------------
 protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater wk = (Repeater)e.Item.FindControl("Repeater2");
            DataRowView row = (DataRowView)e.Item.DataItem;
            string pid = row["id"].ToString();
            wk.DataSource =db.getDS(pid );//注意pid这里是Repeater1的主键值
            wk.DataBind();
        }
    }


dalalist和Repeater类似,把控件名改过来就可以了 --------------------编程问答-------------------- 贴贴你的页面代码(样式都不要),还有打算在什么事件中得到 --------------------编程问答-------------------- <td >
                    <asp:DataList ID="DataList1" runat="server" DataSourceID="ObjectDataSource1" DataKeyField="ID">
                        <ItemTemplate>
                            <asp:Label ID="IDLabel" runat="server" Text='<%# Eval("ID") %>' Visible="false" ></asp:Label><br />
                            试题名称:
                            <asp:Label ID="SS_IDLabel" runat="server" Text='<%# GetTitle(Eval("SS_ID")) %>'></asp:Label><br />
                             <br />
                            <asp:DataList ID="DataList2" runat="server" DataSourceID="ObjectDataSource2">
                                <ItemTemplate>
                                    <asp:Label ID="IDLabel1" runat="server" Text='<%# Eval("ID") %>' Visible="false" ></asp:Label>
                                    <asp:RadioButton ID="RadioButton1" runat="server" GroupName="r1" />
                                    <asp:Image ID="Image1" runat="server" />
                                    <asp:TextBox ID="TextBox1" runat="server" Visible='<%# GetEnter(Eval("SSOEnter")) %>'></asp:TextBox>
                                </ItemTemplate>
                            </asp:DataList> 
                        </ItemTemplate>
                    </asp:DataList></td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" Text="保存" OnClick="Button1_Click" /></td>
            </tr>
        </table>
    
    </div>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetAllStuChooseSingleBySQDID" TypeName="StuSingleDAL">
            <SelectParameters>
                <asp:SessionParameter Name="intSQDID" SessionField="SQDID" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
          
        <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetAllStuSingleOptions" TypeName="StuSingleDAL">
            <SelectParameters>
                <asp:ControlParameter ControlID="DataList1" Name="intID" PropertyName="SelectedValue"
                    Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
    </form>

具体就是这样的 --------------------编程问答-------------------- 帮顶


-
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,