Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspdotnet_website_programming thread: template columns in data grid


Message #1 by "lewis bass" <lewis@t...> on Thu, 4 Apr 2002 00:34:03
I want to use a drop down list in a template column.

I can not seem to find a way to set the selected value of the field - like 
i can with a textbox

Anyone ever done this????
Message #2 by vop@i... on Thu, 4 Apr 2002 09:33:52
Try this one:

int index = 0;
Control cGameCategory = EditReview.Items[0].FindControl("GameCategory");
((DropDownList) cGameCategory).DataTextField  = "txt_kategoria";
((DropDownList) cGameCategory).DataValueField = "id_kategoria";
string         Sql      = "SELECT * FROM categories ORDER BY txt_kategoria 
ASC";
SqlDataAdapter Adapter  = new SqlDataAdapter(Sql, Spojenie);
DataSet        Ds       = new DataSet();
Adapter.Fill(Ds, "categories");
((DropDownList) cGameCategory).DataSource = Ds.Tables["categories"];
((DropDownList) cGameCategory).DataBind();

for (int i=0;i<Ds.Tables["categories"].Rows.Count;i++) {
   object oActCat = Ds.Tables["categories"].Rows[i][Ds.Tables
   ["categories"].Columns["id_kategoria"]];
   string sActCat = Convert.ToString(oActCat);
   if (sActCat == sCat) {
	index = i;
	break;
   }
}
((DropDownList) cGameCategory).SelectedIndex = index;

variable "sCat" value is "categoryID" from SQL Table which is bound with 
the categories table, example: There is table with game reviews, each game 
has its own categoryID, which is stored in SQL Table categories ...
Message #3 by "Lewis Bass" <lewis@t...> on Thu, 4 Apr 2002 14:36:47 -0700
Where i am having my problems is the aspx page itself how do you get the
dropdown to have the value of the field selected before the user changes it.

I can access the value when the user is done with it but how do i set it up
in the first place?
----- Original Message -----
From: <vop@i...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Thursday, April 04, 2002 9:33 AM
Subject: [aspdotnet_website_programming] Re: template columns in data grid


> Try this one:
>
> int index = 0;
> Control cGameCategory = EditReview.Items[0].FindControl("GameCategory");
> ((DropDownList) cGameCategory).DataTextField  = "txt_kategoria";
> ((DropDownList) cGameCategory).DataValueField = "id_kategoria";
> string         Sql      = "SELECT * FROM categories ORDER BY txt_kategoria
> ASC";
> SqlDataAdapter Adapter  = new SqlDataAdapter(Sql, Spojenie);
> DataSet        Ds       = new DataSet();
> Adapter.Fill(Ds, "categories");
> ((DropDownList) cGameCategory).DataSource = Ds.Tables["categories"];
> ((DropDownList) cGameCategory).DataBind();
>
> for (int i=0;i<Ds.Tables["categories"].Rows.Count;i++) {
>    object oActCat = Ds.Tables["categories"].Rows[i][Ds.Tables
>    ["categories"].Columns["id_kategoria"]];
>    string sActCat = Convert.ToString(oActCat);
>    if (sActCat == sCat) {
> index = i;
> break;
>    }
> }
> ((DropDownList) cGameCategory).SelectedIndex = index;
>
> variable "sCat" value is "categoryID" from SQL Table which is bound with
> the categories table, example: There is table with game reviews, each game
> has its own categoryID, which is stored in SQL Table categories ...
>

Message #4 by "Lewis Bass" <lewis@t...> on Thu, 4 Apr 2002 15:51:20 -0700
here is my code from my aspx page

 <asp:datagrid>
     <asp:templatecolumn>
           <itemtemplate>
                <asp:textbox id="tba" runat="server"
text="<%databinder.eval(container, "dataitem.name"_ %>' >
                <asp:textbox>
            </itemtemplate>
     </asp:templatecolumn>
     <asp:templatecolumn>
           <itemtemplate>
                <asp:dropdownlist id="ddb" runat="server">
                    <asp:listitem value= "CAT" selected
TRUE>CAT</asp:listitem>
                    <asp:listitem value  = "DOG"
selected="FALSE">DOG</asp:listitem>
                </asp:dropdownlist>
            </itemtemplate>
     </asp:templatecolumn>
</asp:datagrid>


How do I set the listitem selected equal to true or false depending upon the
value of the field ?

Where do I place the databinder.eval(container, "dataitem.name") call?

I tried passing it as avalue like
<asp:listitem value = "CAT" selected='<% compareValue("CAT",
databinder.eval(container, "dataitem.name") )'>

but get an error that databinder is not supported

I have tried to remove the asp:listitem block but got a message that calls
are not supported in this location.


HELP!!!!

Thank you for trying.
----- Original Message -----
From: <vop@i...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Thursday, April 04, 2002 9:33 AM
Subject: [aspdotnet_website_programming] Re: template columns in data grid


> Try this one:
>
> int index = 0;
> Control cGameCategory = EditReview.Items[0].FindControl("GameCategory");
> ((DropDownList) cGameCategory).DataTextField  = "txt_kategoria";
> ((DropDownList) cGameCategory).DataValueField = "id_kategoria";
> string         Sql      = "SELECT * FROM categories ORDER BY txt_kategoria
> ASC";
> SqlDataAdapter Adapter  = new SqlDataAdapter(Sql, Spojenie);
> DataSet        Ds       = new DataSet();
> Adapter.Fill(Ds, "categories");
> ((DropDownList) cGameCategory).DataSource = Ds.Tables["categories"];
> ((DropDownList) cGameCategory).DataBind();
>
> for (int i=0;i<Ds.Tables["categories"].Rows.Count;i++) {
>    object oActCat = Ds.Tables["categories"].Rows[i][Ds.Tables
>    ["categories"].Columns["id_kategoria"]];
>    string sActCat = Convert.ToString(oActCat);
>    if (sActCat == sCat) {
> index = i;
> break;
>    }
> }
> ((DropDownList) cGameCategory).SelectedIndex = index;
>
> variable "sCat" value is "categoryID" from SQL Table which is bound with
> the categories table, example: There is table with game reviews, each game
> has its own categoryID, which is stored in SQL Table categories ...
>

Message #5 by vop@i... on Fri, 5 Apr 2002 09:38:09
so ...
in the void which is filling DataGrid(TextBox id="tba") try following code:

CatorDog = myDataSet.Tables["myTable"].Rows[0][myDataSet.Tables
["myTable"].Columns["CatOrDog"]];
Control cDDB = myDataGrid.Items[0].FindControl("ddb");

if (CatorDog == "CAT") {
   ((DropDownList) cDDB).SelectedIndex = 0;
}
else if (CatorDog == "DOG") {
   ((DropDownList) cDDB).SelectedIndex = 1;
}
Message #6 by "Lewis Bass" <lewis@t...> on Fri, 5 Apr 2002 08:28:39 -0700
I HONNESTLY DO NOT KNOW HOW TO THANK YOU ENOUGH!

Sometimes I feel very lost and you provided the key .....

THANK YOU!

Lewis

----- Original Message -----
From: <vop@i...>
To: "Website Programming with ASP.NET"
<aspdotnet_website_programming@p...>
Sent: Friday, April 05, 2002 9:38 AM
Subject: [aspdotnet_website_programming] Re: template columns in data grid


> so ...
> in the void which is filling DataGrid(TextBox id="tba") try following
code:
>
> CatorDog = myDataSet.Tables["myTable"].Rows[0][myDataSet.Tables
> ["myTable"].Columns["CatOrDog"]];
> Control cDDB = myDataGrid.Items[0].FindControl("ddb");
>
> if (CatorDog == "CAT") {
>    ((DropDownList) cDDB).SelectedIndex = 0;
> }
> else if (CatorDog == "DOG") {
>    ((DropDownList) cDDB).SelectedIndex = 1;
> }
>


  Return to Index