views:

581

answers:

1

Hello All... I tried posting this before with only text...there was only one response the suggested I update onblur..which didn't seem like the best route as there could be a considerable amount of records: I have the following Gridview built during a repeater ItemDataBound event: '>

            <asp:GridView ID="gvBeneficiary" DataKeyNames="BeneficiaryKey" OnRowCommand="gvBeneficiary_RowCommand" runat="server" AutoGenerateColumns="false">
            <Columns>


                 <asp:TemplateField HeaderText="Name">
                 <ItemTemplate>
                 <asp:HyperLink runat = "server" ID="hlEditBeneficiary" NavigateUrl='<%# "~/EditBeneficiary.aspx?bk=" + HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "BeneficiaryKey").ToString()) %>' Text='<%#Eval("FirstName") %>'></asp:HyperLink>  
                 </ItemTemplate>


                 </asp:TemplateField>  

                <asp:BoundField DataField="Relationship" HeaderText="Relationship" />
                <asp:TemplateField HeaderText="Shares %">

                    <ItemTemplate>
                        <asp:TextBox ID="txtEditShares" runat="server" Text='<%#Bind("Shares") %>'></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Beneficiary Type">

                <ItemTemplate>
                    <asp:DropDownList ID="ddlBeneficiaryType" runat="server" SelectedIndex='<%# GetSelectedBeneficiaryType(Eval("BeneficiaryType")) %>' DataSource='<%# BeneficiaryTypes %>' ></asp:DropDownList>

                </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                <ItemTemplate>
                <asp:LinkButton  Text="Delete" CommandName='DoDelete'  CommandArgument='<%# string.Format("{0}|{1}", Eval("BeneficiaryKey"), Eval("PlanTypeKey")) %>' ID="lbDoDelete" runat="server"></asp:LinkButton>
                </ItemTemplate>

                </asp:TemplateField>          




            </Columns>

            </asp:GridView>
            <asp:HyperLink ID="hlAddBeneficiary" runat="server" Text="Add Beneficiary" NavigateUrl='<%# "~/AddEditBeneficiary.aspx?PT=" + HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "PlanTypeKey").ToString()) + "&CPT=" + HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem, "CorePlanType").ToString()) %>'></asp:HyperLink>

This is the codebehind: protected void rptPlanTypes_ItemDataBound(object sender, RepeaterItemEventArgs e) { GridView gvBeneficiary = (GridView) e.Item.FindControl("gvBeneficiary");

        gvBeneficiary.DataSource = ((PlanType) e.Item.DataItem).BeneficiaryCollection;

        gvBeneficiary.DataBind();
    }

I Have one onclick event from a button that I want to do all the updates from. Anyone have any idea how to drill down the the individual controls on the rows to pull the all the data at once or in a loop. Thanks again for all of your suggestions. Padawan

A: 

You will want to iterate over each row of the GridView and collect the data from each control in which you are interested. For example, the following snippet will grab each txtEditShares value per row.

foreach (GridViewRow row in gvBeneficiary.Rows)
{
    var txtEditShares = (TextBox)row.FindControl("txtEditShares");
    var shares = txtEditShares.Text;
    ///...
}

You'll need to put together the guts of the loop, but that's how move through each row of a GridView and grab control values. I hope it helps.

Ben Griswold