How to assign ID to datagrid's dropdownlist

Results 1 to 2 of 2

Thread: How to assign ID to datagrid's dropdownlist

  1. #1
    Join Date
    Dec 1969

    Default How to assign ID to datagrid's dropdownlist

    I have created a datagrid with item template and edit item template.<BR>I have created a dropdownlist and htmlInputText in edit item template.<BR>Now, datagrid automatically assigns the ID to dropdownlist at runtime.<BR>for eg:- DataGrid1__ctl3_ostatus<BR><BR>I want to set the ID to the dropdown so that I can do some javascript validation.<BR>checkawb is the javascript validation which I have written inside the script tag.<BR><BR>In itemdatabound property of datagrid I have written the following code.<BR><BR>If e.Item.ItemType &#060;&#062; ListItemType.Header And e.Item.ItemType &#060;&#062; ListItemType.Footer Then<BR> If e.Item.ItemType = ListItemType.EditItem Then<BR> Dim dropselect As New DropDownList()<BR> dropselect = CType(e.Item.FindControl("ostatus"), DropDownList) <BR> dropselect.ID="test1" //THIS DOES NOT WORK.<BR> Dim savebutton As New Button()<BR> savebutton = CType(e.Item.FindControl("cmdsave"), Button)<BR> savebutton.Attributes.Add("onclick", "checkawb_(document.frmorder.test1.value);")<B R> End If<BR>End If <BR><BR>How to assign this test1 to dropdownlist ID in edit item template? sothat I can access through "document.frmorder.test1.value"<BR>OR<BR>How to access the ID of that specific dropdownlist?(Also I could not get this ID in itemdatabound)<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: How to assign ID to datagrid's dropdownli

    Not sure I am getting what ur doing but in C# it&#039;s like this....<BR>public void myBound(Object sender, DataGridItemEventArgs e)<BR> {<BR> if(e.Item.ItemType.ToString() != "Footer" && e.Item.ItemType.ToString() != "Header")<BR> {<BR> DropDownList dropSelect = (DropDownList)e.Item.FindControl("DropDown1");<BR> Button button = (Button)e.Item.FindControl("Button1"); <BR> button.Attributes.Add("onclick", "myFunction(\""+dropSelect.ClientID+"\")");<BR > }<BR> }<BR><BR>of course u have to have the OnItemDataBound of the grid pointing to this function. Now with this example its gonna call the javascript function process it and then submit to the server and not sure thats what your looking for. <BR><BR><BR>GoodLuck!<BR><BR>

Posting Permissions

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