3 Replies - 5434 Views - Last Post: 28 February 2008 - 07:58 AM Rate Topic: -----

#1 thecornflake  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 16
  • Joined: 26-September 06

Gridview bound to key value of another - click twice issue

Posted 22 January 2008 - 05:36 AM

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 January 2008 - 05:37 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Gridview bound to key value of another - click twice issue

#2 Nayana  Icon User is offline

  • DIC Hawk - 나야나 नयन:
  • member icon

Reputation: 31
  • View blog
  • Posts: 824
  • Joined: 14-November 07

Re: Gridview bound to key value of another - click twice issue

Posted 22 January 2008 - 07:48 PM

Could you please post code, and :code:
Was This Post Helpful? 0
  • +
  • -

#3 thecornflake  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 16
  • Joined: 26-September 06

Re: Gridview bound to key value of another - click twice issue

Posted 23 January 2008 - 02:31 AM

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

 <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 -

<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 -

<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 -

<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.
Was This Post Helpful? 0
  • +
  • -

#4 thecornflake  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 16
  • Joined: 26-September 06

Re: Gridview bound to key value of another - click twice issue

Posted 28 February 2008 - 07:58 AM

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1