Welcome to Dream.In.Code
Become an Expert!

Join 150,382 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,199 people online right now. Registration is fast and FREE... Join Now!




Gridview bound to key value of another - click twice issue

 
Reply to this topicStart new topic

Gridview bound to key value of another - click twice issue

thecornflake
22 Jan, 2008 - 04:36 AM
Post #1

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 16


My Contributions
I have two gridviews on a page. One of them has the select command for its datasource set with a parameter that is the datakeyvalue of the other.

So whenever a row is selected in the first one, the key value of that row gets passed as a parameter to the selectcommand of the datasource for the other one, and it shows the relevant rows. Except I have to click the select command twice to show the rows. I've got databind commands all over the placein every event relating to the gridviews, but I can't figure out why it doesn't do it until the second click.

This post has been edited by thecornflake: 22 Jan, 2008 - 04:37 AM
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Gridview Bound To Key Value Of Another - Click Twice Issue
22 Jan, 2008 - 06:48 PM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
Could you please post code, and code.gif
User is offlineProfile CardPM
+Quote Post

thecornflake
RE: Gridview Bound To Key Value Of Another - Click Twice Issue
23 Jan, 2008 - 01:31 AM
Post #3

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 16


My Contributions
I wasn't sure what parts of the code you'd want. Here's the first (parent) gridview -

CODE

<asp:GridView ID="grvservers" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" CellPadding="4" DataKeyNames="serverid" DataSourceID="sdsservers"
        Font-Names="Arial" ForeColor="#333333" GridLines="None" Width="100%" Font-Size="Small" PageSize="15">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:CommandField ShowSelectButton="True" CausesValidation="False" />
            <asp:BoundField DataField="serverid" HeaderText="serverid" InsertVisible="False"
                ReadOnly="True" SortExpression="serverid" Visible="False" />
            <asp:BoundField DataField="servername" HeaderText="Name" SortExpression="servername">
                <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
            <asp:BoundField DataField="servertype" HeaderText="Type" SortExpression="servertype">
                <HeaderStyle HorizontalAlign="Left" />
            </asp:BoundField>
        </Columns>
        <RowStyle BackColor="#EFF3FB" />
        <EditRowStyle BackColor="#2461BF" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>


The second one -

CODE

<asp:GridView ID="grvnotes" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" CellPadding="4" DataKeyNames="noteid"
        DataSourceID="sdsservernotes" Font-Names="Arial" Font-Size="Small" ForeColor="#333333"
        GridLines="Horizontal" HorizontalAlign="Left" Width="100%" EmptyDataText="No notes for this server">
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <Columns>
            <asp:CommandField ShowEditButton="True" />
            <asp:TemplateField ShowHeader="False">
                <ControlStyle ForeColor="Black" />
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
                        OnClientClick="return confirm ( 'Are you sure you want to delete this note?' )" Text="Delete"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="noteid" HeaderText="noteid" InsertVisible="False" ReadOnly="True"
                SortExpression="noteid" Visible="False" />
            <asp:TemplateField HeaderText="Note" SortExpression="notetext">
                <EditItemTemplate>
                    <asp:RequiredFieldValidator ID="rfvservernote" runat="server" BackColor="White" ControlToValidate="TextBox1"
                        ErrorMessage="RequiredFieldValidator">You must enter something into the Note field</asp:RequiredFieldValidator>
                    <asp:TextBox ID="TextBox1" runat="server" CausesValidation="True" Text='<%# Bind("notetext") %>'
                        Width="100%"></asp:TextBox>
                </EditItemTemplate>
                <ItemStyle HorizontalAlign="Left" />
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("notetext") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="dateadded" HeaderText="Added" SortExpression="dateadded" ReadOnly="True" >
                <ItemStyle Width="15%" />
            </asp:BoundField>
            <asp:BoundField DataField="addedby" HeaderText="Added By" SortExpression="addedby" ReadOnly="True" >
                <ItemStyle Width="15%" />
            </asp:BoundField>
        </Columns>
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
        <RowStyle BackColor="#EFF3FB" />
        <EditRowStyle BackColor="#2461BF" />
    </asp:GridView>


The datasource for the first one -

CODE

<asp:SqlDataSource ID="sdsservers" runat="server" ConnectionString="<%$ ConnectionStrings:serverlogConnStr %>"
        SelectCommand="SELECT serverid, servername, vmhost, compendiaversion, servertype FROM Servers where deleted is null and externalflag = @externalflag"
        UpdateCommand="UPDATE Servers SET servername =@servername, compendiaversion =@compendiaversion, servertype =@servertype WHERE serverid = @serverid ">
        <UpdateParameters>
            <asp:Parameter Name="servername" />
            <asp:Parameter Name="compendiaversion" />
            <asp:Parameter Name="servertype" />
            <asp:Parameter Name="serverid" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlextflag" DefaultValue="N" Name="externalflag"
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:SqlDataSource>


The datasource for the second -

CODE

<asp:SqlDataSource ID="sdsservernotes" runat="server" ConnectionString="<%$ ConnectionStrings:serverlogConnStr %>"
        SelectCommand="SELECT [noteid], [notetext], [dateadded], [addedby] FROM [Server_Notes] WHERE ([serverid] = @serverid)" DeleteCommand="DELETE FROM Server_Notes WHERE noteid = @noteid" UpdateCommand="UPDATE Server_Notes SET notetext =@notetext WHERE noteid = @noteid">
        <SelectParameters>
            <asp:ControlParameter ControlID="dvservers" Name="serverid" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="noteid" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="notetext" />
            <asp:Parameter Name="noteid" />
        </UpdateParameters>
    </asp:SqlDataSource>


I do databind() in the selectedindexchanged and the rowcommand events of the first one.
User is offlineProfile CardPM
+Quote Post

thecornflake
RE: Gridview Bound To Key Value Of Another - Click Twice Issue
28 Feb, 2008 - 06:58 AM
Post #4

New D.I.C Head
*

Joined: 26 Sep, 2006
Posts: 16


My Contributions
Bumping this as it's becoming quite a big issue. Several days of Googling haven't revealed any answers yet.

On the same page I have a detailview set up the same way and it works fine, so I assume it's only a problem when using gridviews as the detail display.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:27PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month