开发者

Getting Data from Repeater

Basically the question is:

how do i get the ImageID from a repeater so that i can pass it with a query string on button click?

For example: i need to edit a Image Details , each image have a edit button

As shown below:( generated by repeater)

Getting Data from Repeater

c# code:

var List = new List<Images>();
                foreach (DataRow dr in picture.Rows)
                {
                    DateTime DateTemp =            DateTime.Parse(dr["date"].ToString());
                    var childPhoto = new Images()
                               {
                                    DateTaken = DateTemp.ToString("MM/dd/yyyy"),
                                    PlaceTaken = dr["place"].ToString(),
                                    DetailedInfo = dr["info"].ToString(),
                    开发者_运维知识库                ImageID = dr["ImageId"].ToString()
                               };
                    childList.Add(childPhoto);
                }

                ShowPhotoRepeater.DataSource = List;
                ShowPhotoRepeater.DataBind();
            }
        }
    }

    protected void btnEditChildPhoto_Click(object sender, EventArgs e)
    {

        Response.Redirect("EditPhoto.aspx?ImageID=" + ));
    }

My aspx code:

 <asp:Repeater ID="ShowProfileRepeater" runat="server">
    <ItemTemplate>
    <table> 
        <tr>
            <td width = "15%" rowspan="6"><%--<asp:Image ID="ImgPhoto" runat=server />--%> 
            <%--<asp:Image ID="childImage" ImageUrl="<%#Eval("ImgUrl")%>" runat="server" />--%>  
            <asp:Image ID="childImage" ImageUrl="~/img/missing children pictures/shearwey.jpg" CssClass="content_image" runat="server" /> 
            </td><br />
            <td width = "15%">Name:</td>
            <td width = "70%">
                <asp:Label ID="lblChildName" runat="server" Text='<%#Eval("Name")%>'></asp:Label></td>
            <td >
                <asp:Button ID="btnEditChildProfile" runat="server" Text="Edit"   />
            </td>

        </tr>
        <tr>
            <td width = "15%">Gender:</td>
            <td width = "55%">
                <asp:Label ID="lblChildGender" runat="server" Text='<%#Eval("Gender")%>'></asp:Label></td>
            <td></td>
        </tr>
        <tr>
            <td width = "10%">Date Of Birth:</td>
            <td width = "55%">
                <asp:Label ID="lblChildDOB" runat="server" Text='<%#Eval("DOB")%>'></asp:Label></td>                                  
            <td></td>
        </tr>
        <tr>
            <td width = "10%">Country:</td>
            <td width = "55%">
                <asp:Label ID="lblChildCountry" runat="server" Text='<%#Eval("Country")%>'></asp:Label></td>                                  
            <td></td>
        </tr>
        <tr>
            <td width = "10%">Missing Date:</td>
            <td width = "55%">
                <asp:Label ID="lblChildMissingDt" runat="server" Text='<%#Eval("MissingDt")%>'></asp:Label></td>                                  
            <td></td>
        </tr>
        <tr>
            <td width = "10%">Last Seen Location:</td>
            <td width = "55%">
                <asp:Label ID="lblChildLaseSeenLoc" runat="server" Text='<%#Eval("LastSeenLoc")%>'></asp:Label></td>                                  
            <td></td>
        </tr>

    </table>
    </ItemTemplate>
    </asp:Repeater> 


<asp:Button ID="btnEditChildProfile" runat="server" Text="Edit" CommandArgument='<%# Eval("ImageId")%>'   />



protected void btnEditChildPhoto_Click(object sender, EventArgs e)
{
    var btn = (Button)sender;
    Response.Redirect("EditPhoto.aspx?ImageID=" + btn.CommandArgument));
}

Or

<a href='EditPhoto.aspx?ImageID=<%# Eval("ImageId") %>' >Edit</a>


Instead of using a button use a link button inside the repeater to redirect to the link you want. That way, you won't need a separate event handler for the button.

 <asp:LinkButton PostBackUrl="EditPhoto.aspx?ImageID=<%#Eval("ImageId")%>"></asp:LinkButton>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜