嵌套列表视图

发布于 2024-10-19 00:07:02 字数 610 浏览 1 评论 0原文

我有列表视图,在lisetview中我有另一个列表vie,如嵌套列表视图 lv1--> lv2 和 lv2 内部我有按钮,当我单击按钮而不是插入模板显示时,但如何精细控制 lv2 ....?这是我的代码
Lv1 正常工作,但 lv2 出现问题..?

protected void lv1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "NewRecord")
    {

       lv1.InsertItemPosition = InsertItemPosition.FirstItem;

    }
}

protected void lv2_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "NewRecord")
    {
       //ListView lv2 = (ListView)e.Item.FindControl("lv2");
       //lv2.InsertItemPosition = InsertItemPosition.FirstItem;
    }
}

i have list view and inside lisetview i have another list vie like nested listview
lv1 --> lv2 and inside lv2 i have button when i'll click buttion than insert template show but how can fine control lv2 ....? there is my code
Lv1 is working but lv2 is creating problem..?

protected void lv1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "NewRecord")
    {

       lv1.InsertItemPosition = InsertItemPosition.FirstItem;

    }
}

protected void lv2_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "NewRecord")
    {
       //ListView lv2 = (ListView)e.Item.FindControl("lv2");
       //lv2.InsertItemPosition = InsertItemPosition.FirstItem;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难得心□动 2024-10-26 00:07:02

实际上,您可以通过转换 sender 参数轻松访问 lv2 控件:

protected void lv2_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "NewRecord")
    {
       ListView lv2 = (ListView)sender;
       lv2.InsertItemPosition = InsertItemPosition.FirstItem;
    }
}

Actually, you can easily access your lv2 control by casting sender argument:

protected void lv2_ItemCommand(object sender, ListViewCommandEventArgs e)
{
    if (e.CommandName == "NewRecord")
    {
       ListView lv2 = (ListView)sender;
       lv2.InsertItemPosition = InsertItemPosition.FirstItem;
    }
}
娇俏 2024-10-26 00:07:02

嘿,哈利,我想我很了解瓦卡瓦卡!!
首先,您确定项目模板中的第二个列表视图???
或者是在选择、编辑或插入模板中???

如果它在项目模板中,那么:

要找到第二个列表视图,您应该使用以下代码:
在 vb.net 中:

dim Lv2 as listvew = lv.Item.FindControl("listview2")

在 c# 中:

listvew Lv2 = lv.Item.FindControl("listview2");

然后您必须在 lv2 中找到按钮

button newbtn= lv2.Item.FindControl("UrBtnName");

,然后您可以

看到这是 vb.net 中的代码

Sub buttons(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles LVCategories.ItemCommand
        Try
            Select Case e.CommandName

                Case "Delete"
                    'this to take a value from any control
                    Dim Idlabel As Label = e.Item.FindControl("CatIDLabel")
                    Session("ID") = Idlabel.Text()
                Case "new"
                    'Show the insert template
                    LVCategories.InsertItemPosition = InsertItemPosition.FirstItem
                Case "Cancel"
                    'Hide code
                    LVCategories.InsertItemPosition = InsertItemPosition.None

                Case "Edit"
                    'Hide code
                    LVCategories.InsertItemPosition = InsertItemPosition.None

                Case "Update"
                    Dim PictureIDlbl As Label = LVCategories.EditItem.FindControl("ImageIDLabel")
                    '
                    Dim fu As FileUpload = LVCategories.EditItem.FindControl("FileUpload")
                    If fu.HasFile Then

                        Dim PictureID As String = PictureIDlbl.Text()
                        Session("ImageID") = PictureID.ToString

                        Dim filepath As String = Path.Combine(Server.MapPath("~/ADMIN/ImageUpload/Categories/"), PictureID + ".jpg")
                        fu.SaveAs(filepath)
                    End If
                Case "Insert"
                    'Uploader Code
                    Dim fu As FileUpload = LVCategories.InsertItem.FindControl("FileUpload1")
                    Dim ad As New Images()
                    Dim dt As Images.ImagesDataTable
                    ad.DML("1", Nothing, "Categories", "Category Image")
                    dt = ad.Read("3", Nothing, Nothing)
                    Dim DR As DataRow = dt.Rows(0)
                    Dim Imgid As String = DR.Item("ImageID")
                    Session("ImageID") = Imgid.ToString
                    If fu.HasFile Then
                        Dim filepath As String = Path.Combine(Server.MapPath("~/ADMIN/ImageUpload/Categories/"), Imgid + ".jpg")
                        fu.SaveAs(filepath)
                    End If
                    'Hiding the insert template
                    LVCategories.InsertItemPosition = InsertItemPosition.None
            End Select

        Catch ex As Exception

        End Try


    End Sub

,您可以在 C# 中看到此代码:

public void buttons(object sender, ListViewCommandEventArgs e)
{
try {
    switch (e.CommandName) {

        case "Delete":
            //this to take a value from any control
            Label Idlabel = e.Item.FindControl("CatIDLabel");
            Session("ID") = Idlabel.Text();
            break;
        case "new":
            //Show the insert template
            LVCategories.InsertItemPosition = InsertItemPosition.FirstItem;
            break;
        case "Cancel":
            //Hide code
            LVCategories.InsertItemPosition = InsertItemPosition.None;

            break;
        case "Edit":
            //Hide code
            LVCategories.InsertItemPosition = InsertItemPosition.None;

            break;
        case "Update":
            Label PictureIDlbl = LVCategories.EditItem.FindControl("ImageIDLabel");
            //
            FileUpload fu = LVCategories.EditItem.FindControl("FileUpload");

            if (fu.HasFile) {
                string PictureID = PictureIDlbl.Text();
                Session("ImageID") = PictureID.ToString();

                string filepath = Path.Combine(Server.MapPath("~/ADMIN/ImageUpload/Categories/"), PictureID + ".jpg");
                fu.SaveAs(filepath);
            }
            break;
        case "Insert":
            //Uploader Code
            FileUpload fu = LVCategories.InsertItem.FindControl("FileUpload1");
            Images ad = new Images();
            Images.ImagesDataTable dt = default(Images.ImagesDataTable);
            ad.DML("1", null, "Categories", "Category Image");
            dt = ad.Read("3", null, null);
            DataRow DR = dt.Rows(0);
            string Imgid = DR["ImageID"];
            Session("ImageID") = Imgid.ToString();
            if (fu.HasFile) {
                string filepath = Path.Combine(Server.MapPath("~/ADMIN/ImageUpload/Categories/"), Imgid + ".jpg");
                fu.SaveAs(filepath);
            }
            //Hiding the insert template
            LVCategories.InsertItemPosition = InsertItemPosition.None;
            break;
    }


} catch (Exception ex) {
}
}

此示例中有很多示例可以了解如何操作在列表视图中找到一个控件,

谢谢,祝你好运。

hey Hary i think i know very well waqa waqa!!
First of all ,are you sure that the second list view in the item template???
or is it in the select , edite Or insert template ???

if it's in the item template then :

to find the second list view you should use this code :
in vb.net:

dim Lv2 as listvew = lv.Item.FindControl("listview2")

in c# :

listvew Lv2 = lv.Item.FindControl("listview2");

then you have to find your button inside that lv2

button newbtn= lv2.Item.FindControl("UrBtnName");

then you can

see this is the code in vb.net

Sub buttons(ByVal sender As Object, ByVal e As ListViewCommandEventArgs) Handles LVCategories.ItemCommand
        Try
            Select Case e.CommandName

                Case "Delete"
                    'this to take a value from any control
                    Dim Idlabel As Label = e.Item.FindControl("CatIDLabel")
                    Session("ID") = Idlabel.Text()
                Case "new"
                    'Show the insert template
                    LVCategories.InsertItemPosition = InsertItemPosition.FirstItem
                Case "Cancel"
                    'Hide code
                    LVCategories.InsertItemPosition = InsertItemPosition.None

                Case "Edit"
                    'Hide code
                    LVCategories.InsertItemPosition = InsertItemPosition.None

                Case "Update"
                    Dim PictureIDlbl As Label = LVCategories.EditItem.FindControl("ImageIDLabel")
                    '
                    Dim fu As FileUpload = LVCategories.EditItem.FindControl("FileUpload")
                    If fu.HasFile Then

                        Dim PictureID As String = PictureIDlbl.Text()
                        Session("ImageID") = PictureID.ToString

                        Dim filepath As String = Path.Combine(Server.MapPath("~/ADMIN/ImageUpload/Categories/"), PictureID + ".jpg")
                        fu.SaveAs(filepath)
                    End If
                Case "Insert"
                    'Uploader Code
                    Dim fu As FileUpload = LVCategories.InsertItem.FindControl("FileUpload1")
                    Dim ad As New Images()
                    Dim dt As Images.ImagesDataTable
                    ad.DML("1", Nothing, "Categories", "Category Image")
                    dt = ad.Read("3", Nothing, Nothing)
                    Dim DR As DataRow = dt.Rows(0)
                    Dim Imgid As String = DR.Item("ImageID")
                    Session("ImageID") = Imgid.ToString
                    If fu.HasFile Then
                        Dim filepath As String = Path.Combine(Server.MapPath("~/ADMIN/ImageUpload/Categories/"), Imgid + ".jpg")
                        fu.SaveAs(filepath)
                    End If
                    'Hiding the insert template
                    LVCategories.InsertItemPosition = InsertItemPosition.None
            End Select

        Catch ex As Exception

        End Try


    End Sub

and you can see this code in C#:

public void buttons(object sender, ListViewCommandEventArgs e)
{
try {
    switch (e.CommandName) {

        case "Delete":
            //this to take a value from any control
            Label Idlabel = e.Item.FindControl("CatIDLabel");
            Session("ID") = Idlabel.Text();
            break;
        case "new":
            //Show the insert template
            LVCategories.InsertItemPosition = InsertItemPosition.FirstItem;
            break;
        case "Cancel":
            //Hide code
            LVCategories.InsertItemPosition = InsertItemPosition.None;

            break;
        case "Edit":
            //Hide code
            LVCategories.InsertItemPosition = InsertItemPosition.None;

            break;
        case "Update":
            Label PictureIDlbl = LVCategories.EditItem.FindControl("ImageIDLabel");
            //
            FileUpload fu = LVCategories.EditItem.FindControl("FileUpload");

            if (fu.HasFile) {
                string PictureID = PictureIDlbl.Text();
                Session("ImageID") = PictureID.ToString();

                string filepath = Path.Combine(Server.MapPath("~/ADMIN/ImageUpload/Categories/"), PictureID + ".jpg");
                fu.SaveAs(filepath);
            }
            break;
        case "Insert":
            //Uploader Code
            FileUpload fu = LVCategories.InsertItem.FindControl("FileUpload1");
            Images ad = new Images();
            Images.ImagesDataTable dt = default(Images.ImagesDataTable);
            ad.DML("1", null, "Categories", "Category Image");
            dt = ad.Read("3", null, null);
            DataRow DR = dt.Rows(0);
            string Imgid = DR["ImageID"];
            Session("ImageID") = Imgid.ToString();
            if (fu.HasFile) {
                string filepath = Path.Combine(Server.MapPath("~/ADMIN/ImageUpload/Categories/"), Imgid + ".jpg");
                fu.SaveAs(filepath);
            }
            //Hiding the insert template
            LVCategories.InsertItemPosition = InsertItemPosition.None;
            break;
    }


} catch (Exception ex) {
}
}

there are lots of example in this sample to know how to find a control in list view

thanks and good luck for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文