locked
DropDownList in GridView Entity Framework in ASPX webform. RRS feed

  • Question

  • Hi all. I am using the RowEditing for my databound GridView I am trying to access a DropDownList I am not able to get it in code even when I get the name spelled right - any ideas? It always returns nothing.

    Dim row As GridViewRow = gvEditor.Rows(e.NewEditIndex)

    Dim ddl As DropDownList = TryCast(row.FindControl("ddl"), DropDownList)

    I also cannot cast my Entity item from the row.DataItem.

    Dim obj As EntObj = CType(row.DataItem, EntObj)


    Saturday, January 26, 2013 5:20 PM

Answers

  • Hi MadNessIsMine,

    For how to convert row.DataItem to EntObj, I mean something like this:

    DataRowView rowView = (DataRowView)row.DataItem;
    EntObj obj = new EntObj();
    obj.PropertyA = rowView["state"].ToString();//Assign value and use the correct type manually.
    ...

    If you have any problem related to ASP.NET controls, I recommend you try this specific forum for better support: http://forums.asp.net/

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by MadnessIsMine Friday, February 1, 2013 1:52 AM
    Thursday, January 31, 2013 8:02 AM

All replies

  • Hi MadNessIsMine,

    Welcome to the MSDN forum.

    I am not sure if the conversion succeed or not. Please try to assign property values manually.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.



    Monday, January 28, 2013 6:23 AM
  • Not sure I follow what your saying. Could you elaborate?
    Wednesday, January 30, 2013 4:20 AM
  • Hi MadNessIsMin,

    Sorry for this mistake in my writing. Did you encounter any exception? If so, please let me know the specific error message. If the conversion failed, please try to convert it manually.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 30, 2013 7:34 AM
  • 'Convert it manually' - never heard that term. This should be as manual as I can get. There is no error since it did not convert with TryCast. 
    Wednesday, January 30, 2013 1:38 PM
  • Some kind of example?
    Thursday, January 31, 2013 2:11 AM
  • Hi MadNessIsMine,

    For how to convert row.DataItem to EntObj, I mean something like this:

    DataRowView rowView = (DataRowView)row.DataItem;
    EntObj obj = new EntObj();
    obj.PropertyA = rowView["state"].ToString();//Assign value and use the correct type manually.
    ...

    If you have any problem related to ASP.NET controls, I recommend you try this specific forum for better support: http://forums.asp.net/

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by MadnessIsMine Friday, February 1, 2013 1:52 AM
    Thursday, January 31, 2013 8:02 AM