[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Update Row in nested Gridview

Posted on 2009-07-15
5
Medium Priority
?
1,358 Views
Last Modified: 2012-06-21
I have a nested Gridview that displays accounts based on the parent gridview record.  Switching to Edit mode for the rows in the nested seems to work, but the Update function only works for the first row. If you select any row other than the first, the .EditIndex and SelectedIndex = -1
Protected Sub grdProducersList_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles grdProducersList.RowUpdating
        Dim iRow As Integer = e.RowIndex
        Dim grdAccounts As GridView = CType(grdProducersList.Rows(iRow).FindControl("grdAccounts"), GridView)
        'Dim iRow2 As Integer = grdAccounts.EditIndex
        'Dim ddlsecurity As DropDownList = CType(grdAccounts.Rows(iRow2).FindControl("ddlsecurity"), DropDownList)
        Dim srcAccounts As SqlDataSource = CType(grdProducersList.Rows(iRow).FindControl("srcAccounts"), SqlDataSource)
        Dim grdRow As GridViewRow = grdAccounts.Rows(grdAccounts.EditIndex)
        Dim ddlsecurity As DropDownList = CType(grdRow.FindControl("ddlSecurity"), DropDownList)
        'For Each row As GridViewRow In grdAccounts.Rows
        'Dim ddlsecurity As DropDownList = CType(row.FindControl("ddlSecurity"), DropDownList)
        srcAccounts.UpdateParameters("Security").DefaultValue = ddlsecurity.SelectedValue.ToString
        'Next
        ' Dim ddlSecurity As DropDownList = CType(grdAccounts.SelectedRow.FindControl("ddlSecurity"), DropDownList)
 
 
    End Sub
 
Protected Sub grdProducersLIst_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdProducersList.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim CompanyID As String = CType(DataBinder.Eval(e.Row.DataItem, "CompanyID"), String)
            Dim CoopID As String = CType(DataBinder.Eval(e.Row.DataItem, "CoopID"), String)
            'Dim srcAccounts As SqlDataSource = CType(e.Row.FindControl("srcAccounts"), SqlDataSource)
            Dim srcAccounts As SqlDataSource = CType(e.Row.FindControl("srcAccounts"), SqlDataSource)
            srcAccounts.SelectParameters("CoopID").DefaultValue = CoopID.ToString
            srcAccounts.SelectParameters("CompanyID").DefaultValue = CompanyID.ToString
 
        End If
    End Sub
 
<asp:GridView ID="grdProducersList" runat="server" DataSourceID="srcProducerList"
                                AutoGenerateColumns="false" ShowHeader="false" GridLines="none" OnRowDataBound="grdProducersList_RowDataBound">
                                <Columns>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <%#Eval("CompanyName") %>
                                            <asp:GridView ID="grdAccounts" runat="server" DataSourceID="srcAccounts" AutoGenerateColumns="false"
                                                AutoGenerateEditButton="true" DataKeyNames="UID" OnRowUpdating="grdProducersList_RowUpdating">
                                                <Columns>
                                                    <asp:BoundField HeaderText="Account" DataField="username" />
                                                    <asp:BoundField HeaderText="Password" DataField="pword" />
                                                    <asp:CheckBoxField HeaderText="Active" DataField="Active" />
                                                    <asp:CheckBoxField HeaderText="Multi" DataField="Multi" />
                                                    <asp:TemplateField HeaderText="Security">
                                                        <ItemTemplate>
                                                            <%# Security_Display(Eval("Security")) %>
                                                        </ItemTemplate>
                                                        <EditItemTemplate>
                                                            <asp:DropDownList ID="ddlSecurity" runat="server" SelectedValue='<%# Security_Value(Bind("Security")) %>'
                                                                AppendDataBoundItems="true">
                                                                <asp:ListItem Text="Full Access" Value="F"></asp:ListItem>
                                                                <asp:ListItem Text="Limited Access" Value="L"></asp:ListItem>
                                                            </asp:DropDownList>
                                                        </EditItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                            </asp:GridView>
                                            <asp:SqlDataSource ID="srcAccounts" runat="server" ConnectionString='<%$ ConnectionStrings:QMSMisc %>'
                                                SelectCommand="select uid,username,pword,active,multi,security from twaccount where typeid='p' and coopid=@CoopID and companyID=@CompanyID"
                                                UpdateCommand="update twaccount set username=@Username, pword=@Pword, active=@active, multi=@multi, security=@Security where uid=@UID">
                                                <SelectParameters>
                                                    <asp:Parameter Name="CoopID" />
                                                    <asp:Parameter Name="CompanyID" />
                                                </SelectParameters>
                                                <UpdateParameters>
                                                    <asp:Parameter Name="UserName" />
                                                    <asp:Parameter Name="Pword" />
                                                    <asp:Parameter Name="Active" />
                                                    <asp:Parameter Name="Multi" />
                                                    <asp:ControlParameter Name="Security" />
                                                </UpdateParameters>
                                            </asp:SqlDataSource>
                                            <hr />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            <asp:SqlDataSource ID="srcProducerList" runat="server" ConnectionString='<%$ ConnectionStrings:MIMS %>'
                                SelectCommand="select coopID, ProdID + ', ' + ProdName as 'CompanyName',ProdID as 'CompanyID' from TCProducer where active = 1 and CoopID='Select' order by prodid">
                            </asp:SqlDataSource>

Open in new window

0
Comment
Question by:Cahl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 24871196
just an idea....did you try using e.RowIndex instead of EditIndex ..and i believe SelectedIndex will be -1.
0
 

Author Comment

by:Cahl
ID: 24872091
Thanks, for the reply. I'm using e.RowIndex to get the row of grdProducersList, but I'm having trouble either understanding the whole nesting thing, and/or getting the row in grdAccounts that is being selected and updated.
0
 

Author Comment

by:Cahl
ID: 24872466
From what I can see, you suggestion to use e.RowIndex works. Since grdAccounts is nested in grdProducersList, how do I determine which row in grdproducerslist the nested gridview is in so I can grab it and the sqldatasource?

I think this is close, but how do I determine what the current row is in grdProducersList?
Dim grdAccounts As GridView = CType(grdProducersList.Rows(0).FindControl("grdAccounts"), GridView)
0
 

Author Comment

by:Cahl
ID: 24873986
I believe I figured it out. By using the sender of the  Protected Sub grdProducersList_RowUpdating procedure, I'm able to determie the GridView that fired the event. From this I'm able grab its datasource with   Dim srcAccounts As SqlDataSource = CType(grdAccounts.DataSourceObject, SqlDataSource) and populate the parameter from the dropdownlist.
0
 

Author Closing Comment

by:Cahl
ID: 31603926
Thanks for your help with the RowIndex issue!
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question