Click here to Skip to main content
15,887,596 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionAjax and Asp.net Pin
ahawari0924-Jan-09 1:34
ahawari0924-Jan-09 1:34 
AnswerRe: Ajax and Asp.net Pin
Colin Angus Mackay24-Jan-09 2:49
Colin Angus Mackay24-Jan-09 2:49 
QuestionViewing aspx pages Pin
Ha ha ha ha ha ha ha ha24-Jan-09 1:09
Ha ha ha ha ha ha ha ha24-Jan-09 1:09 
AnswerRe: Viewing aspx pages Pin
Colin Angus Mackay24-Jan-09 1:13
Colin Angus Mackay24-Jan-09 1:13 
GeneralRe: Viewing aspx pages Pin
Ha ha ha ha ha ha ha ha24-Jan-09 1:24
Ha ha ha ha ha ha ha ha24-Jan-09 1:24 
GeneralRe: Viewing aspx pages Pin
Colin Angus Mackay24-Jan-09 1:50
Colin Angus Mackay24-Jan-09 1:50 
AnswerRe: Viewing aspx pages Pin
Abhijit Jana24-Jan-09 2:10
professionalAbhijit Jana24-Jan-09 2:10 
QuestionUnable to display data using Nested gridview with LinqDatasource control Pin
Member 129942624-Jan-09 0:53
Member 129942624-Jan-09 0:53 
Shucks | :-\
Hi
I am using .Net 3.5 .I am using trying to create a Master detail relationship using gridview with LinqDataSource control. I am using northwind database with Categories and Products table.
For every Categoryid, I want to display the corresponding Product details.
I am getting an error which is shown below.

Here is the full code:

<asp:LinqDataSource ID="categoriesLinqDataSource" runat="server"
ContextTypeName="NorthwindDataContext"
Select="new (CategoryName)"
TableName="Categories">

</asp:LinqDataSource>
<asp:LinqDataSource ID="productsLinqDataSource" runat="server"
ContextTypeName="NorthwindDataContext"
Select="new (ProductID, ProductName, CategoryID, UnitPrice,
UnitsInStock, Discontinued)"
TableName="Products"
Where="CategoryID == @CategoryID">

<WhereParameters>
<asp:Parameter Name="CategoryID" Type="Int32" />
</WhereParameters>

</asp:LinqDataSource>
<br />
<asp:GridView ID="grdcategories" runat="server" AutoGenerateColumns="False"

DataSourceID="categoriesLinqDataSource"
onrowcreated="grdcategories_RowCreated">

<Columns>

&lt;asp:BoundField DataField="CategoryName" HeaderText="CategoryName" />
&lt;asp:TemplateField HeaderText="Products">
&lt;ItemTemplate>
&lt;asp:GridView ID="grdproducts" runat="server"
AutoGenerateColumns="False"
DataKeyNames="ProductID"
DataSourceID="productsLinqDataSource">
&lt;/asp:GridView>
&lt;/ItemTemplate>
&lt;/asp:TemplateField>
&lt;/Columns>
</asp:GridView>

protected void grdcategories_RowCreated(object sender, GridViewRowEventArgs e)
{
var ctx = new NorthwindDataContext(); //Northwind.dbml class
if (e.Row.RowType == DataControlRowType.DataRow)
{
GridView innergridview = e.Row.Cells[1].FindControl("grdproducts") as GridView;

var cat = ctx.Categories.Single(c => c.CategoryName ==
grdcategories.DataKeys[e.Row.DataItemIndex].ToString());


productsLinqDataSource.WhereParameters["CategoryID"].DefaultValue = cat.CategoryID.ToString();

innergridview.DataSource = productsLinqDataSource;
}
}


error: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Could anyone pls let me know what's wrong?</pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre><pre></pre>
QuestionDisable cookieless sessions Pin
AlexeiXX323-Jan-09 20:27
AlexeiXX323-Jan-09 20:27 
AnswerRe: Disable cookieless sessions Pin
DevCubed24-Jan-09 20:07
DevCubed24-Jan-09 20:07 
Question"asp:fileupload" control is not working Pin
Anand Desai23-Jan-09 20:06
Anand Desai23-Jan-09 20:06 
AnswerRe: "asp:fileupload" control is not working Pin
N a v a n e e t h23-Jan-09 23:21
N a v a n e e t h23-Jan-09 23:21 
AnswerRe: "asp:fileupload" control is not working Pin
Hampden Tech24-Jan-09 2:41
Hampden Tech24-Jan-09 2:41 
Questionbest between VB and c# Pin
souravghosh1823-Jan-09 19:40
souravghosh1823-Jan-09 19:40 
AnswerRe: best between VB and c# Pin
Colin Angus Mackay24-Jan-09 1:12
Colin Angus Mackay24-Jan-09 1:12 
AnswerRe: best between VB and c# Pin
Wendelius24-Jan-09 5:07
mentorWendelius24-Jan-09 5:07 
QuestionProblem Regarding Preventing Postback Pin
ais0723-Jan-09 17:21
ais0723-Jan-09 17:21 
AnswerRe: Problem Regarding Preventing Postback Pin
Nishant Singh23-Jan-09 22:50
Nishant Singh23-Jan-09 22:50 
GeneralRe: Problem Regarding Preventing Postback Pin
ais0723-Jan-09 22:53
ais0723-Jan-09 22:53 
QuestionUpdate rows in a gridview Pin
Cyberpulse23-Jan-09 15:36
Cyberpulse23-Jan-09 15:36 
AnswerRe: Update rows in a gridview Pin
N a v a n e e t h23-Jan-09 16:33
N a v a n e e t h23-Jan-09 16:33 
QuestionHow to set a session variable to selected row value Pin
cubangt23-Jan-09 11:55
cubangt23-Jan-09 11:55 
AnswerRe: How to set a session variable to selected row value Pin
Not Active23-Jan-09 14:13
mentorNot Active23-Jan-09 14:13 
Questionxsd serialization question Pin
Member 391904923-Jan-09 10:54
Member 391904923-Jan-09 10:54 
QuestionHow to redirect to the default.aspx page ? Pin
David Mujica23-Jan-09 10:43
David Mujica23-Jan-09 10:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.