GridView.Rows(Column=ID_PK) to GridView.Rows(Column=DropDownListTeamplteField)

Hi Guys,

I wonder how I can assign the PrimaryKey in each GridView Row to the template field in the same row. whereas the template field is filled with a dropdownlist that

should show the values for retrieved in a different table through the GridView Row primary key (which serves as the SELECT parameter to get these values)

 The GridView looks like this:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
        DataKeyNames="C_ID" DataSourceID="GetC_IDs">
        <Columns>
            <asp:BoundField DataField="C_Name" HeaderText="C_Name" SortExpression="C_Name" />
            <asp:BoundField DataField="C_ID" HeaderText="_ID" ReadOnly="True" SortExpression="C_ID"
                InsertVisible="False">
            </asp:BoundField>
            <asp:BoundField DataField="SessionID" HeaderText="SessionID" ReadOnly="True"
                SortExpression="SessionID" InsertVisible="False" Visible="False" />
            <asp:TemplateField HeaderText="C_Values">
                <ItemTemplate>
                    <asp:DropDownList ID="DropDownListC_Values" runat="server" 
                        DataTextField="ValueName" DataValueField="ValueNumber" 
                        ToolTip="Please select a value" DataSourceID="GetC_Values">
                    </asp:DropDownList>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

The Get_CIDs datasource I am not showing because it is working perfectly, the GridView is filled with the C_IDs but the template field (dropdownlist) is not filled with the values for each C_ID.



 the GetC_Values objectdatasource looks like this:

<asp:ObjectDataSource ID="GetC_Values" runat="server" OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetC_Values" TypeName="xxxxdst02CTableAdapterxxx">
        <SelectParameters>
            <asp:QueryStringParameter Name="SessionID" 
                QueryStringField="strSessionID" Type="String" />
            <asp:ControlParameter ControlID="GetSessionC" Name="C_ID"
                Type="String" DefaultValue="NULL" PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:ObjectDataSource>

 
I am trying to fix this since 3 days now. Somehow it does not work.

I am very thankful for any suggestions.

Polynaux

PS: thats how it should look:


 

0
polynaux
1/28/2008 12:11:07 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

13 Replies
887 Views

Similar Articles

[PageSpeed] 18

I wonder if the datasource for the C_Values should be the gridview with its rows or the gridview's datasource, filling the gridview in the first place:

 

0
polynaux
1/28/2008 1:53:08 PM

I wonder if something around the lines of:

 

GetC_Values.SelectParameters(GridViewC_Definition.DataKeys.ToString)

could work, that statement basically says that all datakeys values should be the sql select paramter for the GetC_Values Datasource.
 
unfortunately, this code is not valid   :-/ 
  
0
polynaux
1/28/2008 3:25:49 PM

Add SelectedValue='<%# Bind("C_ID") %>'  to your DropDownList and next to the ddl's datasource.


Limno

0
limno
1/28/2008 3:43:04 PM

Hi Limno, thanks for you help !!

unfourtunately, when I add you suggestion to the ddl's datasource I get the error:

  

    <asp:ObjectDataSource ID="GetC_Values" runat="server" OldValuesParameterFormatString="original_{0}"
        TypeName="dst02SessionFunctionsTableAdapters.aspnet_C_ValuesTableAdapter" 
        SelectMethod="GetC_Values">
        <SelectParameters>
            <asp:QueryStringParameter Name="DSession" QueryStringField="strDecisionSessionID"
                Type="String" DefaultValue="" />
            <asp:ControlParameter ControlID="GridViewC_Definition" 
                DefaultValue="NULL" Name="C_ID" PropertyName="SelectedValue" SelectedValue='<%# Bind("C_ID") %>'
                Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>

 

 Error Creating Control:

Databinding expressions are only supported on objects that have a DataBinding event.
System.Web.UI.WebCntrols.ControlParameter does not have a DataBinding event.

0
polynaux
1/28/2008 4:07:08 PM

<asp:DropDownList ID="DropDownListC_Values" runat="server"
                        DataTextField="ValueName" DataValueField="ValueNumber"
                        ToolTip="Please select a value" DataSourceID="GetC_Values" SelectedValue='<%# Bind("C_ID") %>'>
                    </asp:DropDownList>

<asp:ObjectDataSource ID="GetC_Values" ...>


Limno

0
limno
1/28/2008 4:21:36 PM

ok thanks again,

now I got

'DropDownListC_Values' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

What does this mean ?
 

0
polynaux
1/28/2008 4:36:31 PM

 Hi limno,

I have got rid of the SelectedValue='<xxx and try to do it via a hidden textbox.

By writing this function which is iterating through the GridView1.Rows (C_ID)

 

   For Each row As GridViewRow In GridView1.Rows
            C_ID = row.Cells(0).Text
            TextBox1.Text = C_ID
            GetC_Values.DataBind()
        Next

So the ddl's datasource get the missing parameter form the textbox . so far, the datasource /and textbox is missing the first row but the second row is successfully bound to the ddl
  
0
polynaux
1/28/2008 5:03:47 PM

limno:

<asp:DropDownList ID="DropDownListC_Values" runat="server"
                        DataTextField="ValueName" DataValueField="ValueNumber"
                        ToolTip="Please select a value" DataSourceID="GetC_Values" SelectedValue='<%# Bind("C_ID") %>'>
                    </asp:DropDownList>

<asp:ObjectDataSource ID="GetC_Values" ...>

This is the way to use a DropDownList on a GridView. Most (if not all) of time, people are using it in edit/insert template. Since you mention C_ID is the primary key field of your table, I assume there is no null value in it. Please make sure your C_ID values are included in your DropDownList value list (all values should be included, otherwise you will get the error message you have now.)


Limno

0
limno
1/28/2008 8:14:49 PM

Hi limno,

 the problem is that if I add you suggestions i.e. SelectedValue='<%# Bind("C_ID") %>' then I get the error:

'DropDownListC_Values' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
 
That is right, there is no null value in it. The DropDownList should actually just display ValueName and ValueNumber which are retrieved through C_ID - the C_ID comes from each individual row in the

GridView.

 

Many thanks,

 

polynaux 

0
polynaux
1/29/2008 9:47:36 AM

This also works quite ....well some DropDownLists dont get the right values but at least there is no error and one of the many DropDownLists is binding ..something:

 

 

    For Each row As GridViewRow In GridViewC_Definition.Rows
            C_ID = row.Cells(0).Text
            e.InputParameters("C_ID") = C_ID

        Next
  
0
polynaux
1/29/2008 10:08:08 AM

The problem seems to be that when the system tries to select the item in the dropdownlist, the dorpdownlist does not has that value. make sure that all the values for C_ID that are being bound to the gridview are already there in the dropdownlist


Vikram
www.vikramlakhotia.com


Please mark the answer if it helped you
0
vik20000in
1/29/2008 10:11:15 AM

 Hi vik20000in.

thats quite add, the system does not need to select an item in the dropdownlist, I just want to populate the dropdownlist with the values retrieved through the parameter C_ID which is in each individual row of the GridView.

 

Thanks for shining light on this issue,

 polynaux
 

0
polynaux
1/29/2008 11:39:59 AM

 I really cant believe it, since three days I am trying this "easy" thing now, and it just does not row by row.

0
polynaux
1/29/2008 10:11:06 PM
Reply:

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

How to divide 1 GridView Row with 1 column in 2 Rows with 5 columns?
Hi; I have a GridView with 10 rows and 1 column. How can I do to this GridView show the same data, but with 2 rows and 5 columns? In classic ASP, I made it this way: While (NOT rsFotos.EOF) if i mod 5 = 0 then Response.Write "</tr><tr>" end if ... Someone can help? :)  You have to use a custom template and lay the table out the way you want, either dropping controls in the template or creating a custom ITemplate that takes care of it for you. http://professionalaspnet.com/archive/2006/06/15/Useing-ITemplate-in-the-Data-Controls.aspxChris L...

Adding a row to the last row column in Gridview ?
Hello, I have a gridview and it displays data in row column and I want to add a row across in the bottom of the last row for the total value.  How do I do it?  Thanks Here is my Gridview <Columns> <asp:BoundField DataField="Information" HeaderText="Information" SortExpression="Information" HeaderStyle-Width = "600" HeaderStyle-Wrap = "true"/> </Columns>   use footer? something like maybe.    use TemplateField   <Columns> <asp:BoundField DataField="Infor...

Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once?
 Hi Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once onto the grid? What I mean is some grid that 's as flexible as MS Excel grid for example.  Any suggestions will be very much appreciated.E The Repeater control is a highly customisable data presentation controlRohin.NET developerNever trust a computer you can't throw out a window. - Steve WozniakPlease remember to click on 'Mark as answer', if this post helped you......

How to transform SQL output rows into GridView rows+columns?
This is somewhat tricky to explain. What I am trying to do is link the output from a SQL query that is grouped into rows and turn that into a set of rows and columns. ex: turn this (from SQL): sqlcol1sqlcol2sqlcol3 row_1 col_a 1 row_1 col_b 2 row_1 col_c 3 row_2 col_a 4 row_2 col_b 5  into this (in GridView):  col_acol_bcol_c row_1 1 2 3 row_2 4 5     I am thinking that the best way of doing this is to inherit from GridView and to write a custom metho...

Referencing a gridview column by name when iterating through gridview rows
Can I reference a column by name when iterating though gridview rows in code?  The only way I know is using  cell numbers. Now.......Dim row As GridViewRowDim strValue as StringFor Each row In GridView1.Rows strValue  = row.Cells(10).TextNext I would like it like this.............Dim row As GridViewRowDim strValue as StringFor Each row In GridView1.Rows strValue  = row.Cells("ColumnName").TextNext That's correct. The only way to access the Cells collection is via an ordinal index number.Thanks, EdMicrosoft MVP - ASP/ASP.NET You can convert a...

Data Controls insert rows into gridview then insert rows from gridview into SQL Table
Hello there, I'm still new at performing miracles with code . Currently I am having trouble with my latest coding adventure I have a web application which records jobs and labour assigned to jobs. The issue in particular I'm having is the way in which labour is to be assigned. I want to use standard controls (Textbox, Dropdownlist) to record the values into a gridview (ie,put multiple rows into the gridview using the controls). Then, when all the inserting is complete, the user clicks a submit button to insert all the rows from the gridview into a database table. The reason for...

GridView Row Height and Column Width -Changes based on no. of Rows
Hi ,     I am working on a ASP.NET 3.5 application using GridView control. Height and width of the GridView is not constant when i bind the datatable. If there are more records then it is set properly. But if  there are only 2 or 3 rows, the height of the Row is increased and the width of the Last column is decreased. Is it because scroll bar is not visible when there are less rows?I have set the overflow of the DIV tag to AUTO How to have Fixed Height for the Rows and Fixed Column width irrespective of the number of rows in the GridView?  I am using the follow...

I want to select a row and column in gridview using radiobutton in gridview
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

Hide a Gridview column but use the value in that column when the row is selected.
I need to retrieve a column from my database but do not want to display it in the gridview.  However, I need to be able to show that information later in the application.  I am using the wizard control.  I believe I can use the DataKeyValues property of the gridview but can't figure out how to write the code to get the value of the cell in that column when the row is selected so it can be referenced later.  I am using VB.  Thanks for your help!! Found the answer.  Here it is in case anyone else needs it:       &nbs...

exporting a gridview control with selected rows and columns
Hey I would liket o export only the data not the headers or the controller(edit, delete, etc) how would i go about doing so. This si my code that allows me to export in the first place!Protected Sub btnExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExport.Click   GridView1.AllowPaging = False GridView1.PageSize = 100 GridView1.DataSource = "datasourcePullInst" 'Place your datasource (datatable/dataset) 'GridView1.DataBind() Response.Clear() Response.Buffer = TrueResponse.AddHeader("Content-Disposition", "attachment...

Template column control not Visible in all Gridview rows
I got something odd here.  there is too much code to post, but I have a Template column in a GridView (created in design mode) with a RadioButtonList as the control in that column.  But RadioButtonList does NOT exist in all rows!!!  It shows in some rows.  I am not tinkering with the Visible property.  Oddly enough though, the rows it doesn't show in are the rows with partial data (some dataitems are emptystrings).  But that deosn't make any sense to me.  Anybody seen this before?    jP  I believe you need an e...

I want to select a row and column in gridview using radiobutton in gridview #2
I want to select a row and column in gridview using radiobutton in gridview . if which radio button is select that row will select and i want that row column values in outside individual textboxes of next page.  but in that only single radiobutton will select and no post back="true" bcz iam not using checked change property. i inserted button below gridview. if i click the that selected row and columns values are stored into textboxes of next page im using this code .but im getting one column in that row. but i want all columns in that selected row so plz repla...

Gridview
Hi. What I would like to do is to have a layout like this ID Description SomeOthercolumn ----------------------------------------------------------------------------- ID Short description Text Some other value Long description Text that will span multiple columns ID #2 Short description Text #2 Some other value #2 Long description Text that will span multiple columns #2 Get the picture. This is not a problem with repeaters, because you ha...

Web resources about - GridView.Rows(Column=ID_PK) to GridView.Rows(Column=DropDownListTeamplteField) - asp.net.presentation-controls

Resources last updated: 12/22/2015 11:28:00 PM