Results 1 to 6 of 6

Thread: datagrd in asp.net

  1. #1
    hi all
    plz i ' ve 2 datagrids
    so i want to choose the name of teams in order to display in second datagrid (name,lasnam of players in this team )
    how to do it ????

  2. Internet, Programming and Graphics   -   #2
    Snee's Avatar Error xɐʇuʎs BT Rep: +1
    Join Date
    Sep 2003
    Location
    on something.
    Age
    44
    Posts
    17,985
    A quick way to do it is to have a hyperlink column on the first grid, linking to the page itself, then you pass a team ID or something, like a parameter with the url in the hyperlink column.

    Something like:

    <asp:HyperLinkColumn
    HeaderText="whatever"
    DataTextField="TeamID" DataTextFormatString="click"
    DataNavigateUrlFormatString="yourpage.aspx?TID={0}" DataNavigateUrlField="TeamID">
    </asp:HyperLinkColumn>

    Then you grab that ID on postback, put it in an if so you don't bug out if there's no ID to get, ie If Not Request.QueryString("TID") = "" Then...

    Then you grab players with the relevant TID and put them in the dataset, and then the grid via that, or you always grab all the players and put them in the dataset on every load, and you run a select against the dataset instead when necessary.

    Try avoiding opening up more than one database connection per page, if you are doing something involving a database.

  3. Internet, Programming and Graphics   -   #3
    thinks so mutch Snee

    but plz i don't know {0} and function about it ?
    it's possible to change it by {1} or {2} ...???
    Last edited by cheikhanio; 05-11-2008 at 07:25 PM.

  4. Internet, Programming and Graphics   -   #4
    Snee's Avatar Error xɐʇuʎs BT Rep: +1
    Join Date
    Sep 2003
    Location
    on something.
    Age
    44
    Posts
    17,985
    Don't worry about the zero there, what {0} means there is that it'll create a link on each row with the appropriate TID to go with the Team ID in the row, if I remember right. {1} would be the index for a second parameter, if you need to pass something else along, but hyperlinkcolumns don't allow that, so you have to switch to a templatecolumn or something, you don't need it though.

    So when the link is generated, anyways, it'll not have a {0} on it, but rather the appropriate number.

    I'd probably just loop everything from the dataset or directly from the database to the datatable via a datareader and generate each row myself in a foreach or something, that way I reckon you have more control over exactly what ends up in each row. You can even abbreviate strings you think are too long*. I like that kind of thing better than datagrids.

    Something like this, I mean:
    foreach (DataRow row in dbData.Tables[0].Rows)
    {
    string content = row[0].ToString();
    if (content.Length > 100) { content = content.Substring(0, 97) + "..."; }
    listHolder.InnerHtml += " .:<a href='page.aspx?TID=" + row[1].ToString() + "'>" + content + " &rArr;</a>:.<br />";
    }

    Where listholder would be a div or something. It's C# but you get the general idea. In that example the first column in every row, [0], could hold the Team Name, or something, and the second, [1], could hold the Team ID. dbData would be the dataset.

    Another way to do it would be to pass the team name along rather than a team ID, but then you have to account for spaces and stuff, somehow.

    You should prolly check this out. I'm a bit on the side, atm, so better get some other sources, like.

    *You could probably do that with a boundcolumn or something as well, but like I said, I don't like datagrids all that much, especially now that they don't fit inside of labels and stuff, which makes them more annoying to set up if you want to make them scrollable and stuff like that.
    Last edited by Snee; 05-12-2008 at 05:25 AM.

  5. Internet, Programming and Graphics   -   #5
    thinks so mutch Snee
    i'll pray to u very much

  6. Internet, Programming and Graphics   -   #6
    Snee's Avatar Error xɐʇuʎs BT Rep: +1
    Join Date
    Sep 2003
    Location
    on something.
    Age
    44
    Posts
    17,985
    Err, thanks, and no worries.

    Also remember that as long as you know what components you are working with, information is generally available on the internet, though it might take some getting used to to think up good keywords for searches, I suppose. Especially if english isn't your native language.

    But Google can be really valuable when coding, and can solve nearly anything you might run into with asp.net.

    There's nothing wrong with asking like this, obviously, but discussion boards have always been my last resort, since you always have to wait for answers.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •