This is a migrated thread and some comments may be shown as answers.

ListBox in EditFormSettings

5 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
maha
Top achievements
Rank 1
maha asked on 15 Jul 2008, 04:59 PM
Below is my EditFormSettings code

<EditFormSettings EditFormType="Template">

<FormTemplate>

<table width="100%">

<tr>

<td>

<asp:Label ID="lblUserName" runat="server" Text="User Name"></asp:Label>

</td>

<td>

<asp:TextBox ID="txtUserName" runat="server" Text='<%# Bind("Username") %>'></asp:TextBox>

</td>

</tr>

<tr>

<td>

<asp:Label ID="lblInitialPwd" runat="server" Text="Initial Password"></asp:Label>

</td>

<td>

<asp:TextBox ID="txtInitialPwd" runat="server" Text='<%# Bind("InitialPassword") %>'></asp:TextBox>

</td>

</tr>

<tr>

<td>

<asp:Label ID="lblUserpassword" runat="server" Text="User Password"></asp:Label>

</td>

<td>

<asp:TextBox ID="txtUserpassword" runat="server" Text='<%# Bind("UserPassword") %>'></asp:TextBox>

</td>

</tr>

<tr>

<td>

<asp:Label ID="lblEmail" runat="server" Text="E-mail"></asp:Label>

</td>

<td>

<asp:TextBox ID="txtEmail" runat="server" Text='<%# Bind("Email") %>'></asp:TextBox>

</td>

</tr>

<tr>

<td width="10%">

</td>

<td width="90%">

<table>

<tr>

<td><span style="font-weight:bold; font-size:10pt"></span>

<asp:Label ID="lblAccountNumber" runat="server" Text='<%# Bind("AccountNumber") %>' Font-Bold="true" Font-Size="10"></asp:Label><br />

<asp:ListBox ID="lbAllAccountNumbers" DataSourceID="objAllAccountNumbers" runat="server" Width="200" Height="200"></asp:ListBox>

<asp:Button ID="btnSelect" runat="server" Text=">" />

<asp:Button ID="btnUnselect" runat="server" Text="<" />

<asp:ListBox ID="lbAvailableAccountNumbers" DataSourceID="objAllAccountNumbers" runat="server" Width="200" Height="200">

</asp:ListBox>

</td>

</tr>

</table>

</td>

</tr>

</table>

</FormTemplate>

</EditFormSettings>

I have two SqlDatSource 1 datasource for grid and one for ListBox.
I set up a Datakey name For the grid which will server as the parameter for the ListBox SqlDataSource.

I tried setting up the parameter for ListBox Datasource from Grid ItemDataBound but when doing Find Control method returns null.

below is my code behind

if

(e.Item is GridEditFormItem)

{

ListBox lbAllAccountNumbers = (ListBox)e.Item.FindControl("lbAllAccountNumbers");

SqlDataSource ds = (SqlDataSource)lbAllAccountNumbers.DataSource;

ds.SelectParameters[

"@LoginId"].DefaultValue = grdAffiliate.Items[e.Item.ItemIndex].OwnerTableView.DataKeyValues[e.Item.ItemIndex]["LoginId"].ToString();

lbAllAccountNumbers.DataSource = ds;

lbAllAccountNumbers.DataBind();

}

lbAllAccountNumbers  is getting null value

5 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 16 Jul 2008, 05:22 AM
Hi maha,

Here is an example how to find the ListBox:

if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
    ListBox lbAllAccountNumbers = (ListBox)e.Item.FindControl("lbAllAccountNumbers");
}

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
maha
Top achievements
Rank 1
answered on 16 Jul 2008, 03:41 PM
Where should i include this code ?
I tried in ItemCommand,EditCommand.
The condition

if

(e.Item is GridEditableItem && e.Item.IsInEditMode)

Will not satisfy.


I want to show the listbox items when i click on Edit.

0
Shinu
Top achievements
Rank 2
answered on 17 Jul 2008, 05:13 AM
Hi Maha,

Try the above given code snippet in the ItemDataBound event.

CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            ListBox lbAllAccountNumbers = (ListBox)e.Item.FindControl("lbAllAccountNumbers"); 
        } 
   } 


Shinu.
0
maha
Top achievements
Rank 1
answered on 17 Jul 2008, 03:10 PM
I got the listbox now.But still not able to get the Datakey from the grid, since the item is not bound yet. I have it in SqlDataSource1, is there any way i can get the data from grid' SqlDataSource in grid itemDatabound.
0
Accepted
Princy
Top achievements
Rank 2
answered on 18 Jul 2008, 06:00 AM
Hi Maha,

You can access the DataKeyName in the ItemDataBound event as shown below.

ASPX:
<MasterTableView DataSourceID="SqlDataSource2" DataKeyNames="Project_Name"
</MasterTableView> 

CS:
protected void  RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
  { 
     if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode)) 
        { 
         GridEditableItem edititem = (GridEditableItem)e.Item; 
         string key = edititem.GetDataKeyValue("Project_Name").ToString(); 
        } 
  } 

Thanks
Princy.
Tags
Grid
Asked by
maha
Top achievements
Rank 1
Answers by
Vlad
Telerik team
maha
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Princy
Top achievements
Rank 2
Share this question
or