Hi,
I want to add a dropdown and a button in radgrid. The values in the dropdown are static(for example: "male" and "female").
I want to have the dropdown and button in the inseritemtemplate and edititemtemplate as well . Foe the button how should the aspx.cs be invoked?
How to add and use the dropdown and button in radgrid
Thanks
I want to add a dropdown and a button in radgrid. The values in the dropdown are static(for example: "male" and "female").
I want to have the dropdown and button in the inseritemtemplate and edititemtemplate as well . Foe the button how should the aspx.cs be invoked?
How to add and use the dropdown and button in radgrid
Thanks
5 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 24 Dec 2012, 07:08 AM
Hi,
Please take a look into the following code snippet.
ASPX:
C#:
Please take a look into the following code snippet.
ASPX:
<
telerik:GridTemplateColumn
>
<
EditItemTemplate
>
<
asp:DropDownList
ID
=
"DropDown1"
runat
=
"server"
>
<
asp:ListItem
Text
=
"Male"
></
asp:ListItem
>
<
asp:ListItem
Text
=
"Female"
></
asp:ListItem
>
</
asp:DropDownList
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Button1"
OnClick
=
"Button1_Click"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
//your code
}
Thanks,
Shinu.
0

Venkatesh
Top achievements
Rank 1
answered on 26 Dec 2012, 09:28 AM
Hi,
Thanks for the reply.
Can the same code be used in InsertItemTemplate and ItemTemplate also?
I am trying to have columns as below:
dropdown, textbox, button, textbox, textbox
The user selects a value in the dropdown and adds some value in the second textbox and clicks on the button. The 4th and 5th textbox in grid should be filled with data from database depending on the dropdown value and textbox.
The grid columns should be available in InsertItemTemplate, Edititemtemplate, Itemtemplate.
Thanks
Thanks for the reply.
Can the same code be used in InsertItemTemplate and ItemTemplate also?
I am trying to have columns as below:
dropdown, textbox, button, textbox, textbox
The user selects a value in the dropdown and adds some value in the second textbox and clicks on the button. The 4th and 5th textbox in grid should be filled with data from database depending on the dropdown value and textbox.
The grid columns should be available in InsertItemTemplate, Edititemtemplate, Itemtemplate.
Thanks
0

Shinu
Top achievements
Rank 2
answered on 26 Dec 2012, 09:47 AM
Hi,
You can use the same in the InsertItemTemplate and ItemTemplate as well. Please take a look into the following code snippet.
ASPX:
C#:
Thanks,
Shinu.
You can use the same in the InsertItemTemplate and ItemTemplate as well. Please take a look into the following code snippet.
ASPX:
<
telerik:GridTemplateColumn
>
<
EditItemTemplate
>
<
asp:DropDownList
ID
=
"DropDown1"
runat
=
"server"
>
<
asp:ListItem
Text
=
"Male"
></
asp:ListItem
>
<
asp:ListItem
Text
=
"Female"
></
asp:ListItem
>
</
asp:DropDownList
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
></
asp:TextBox
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Button1"
OnClick
=
"Button1_Click"
/>
<
asp:TextBox
ID
=
"TextBox2"
runat
=
"server"
></
asp:TextBox
>
<
asp:TextBox
ID
=
"TextBox3"
runat
=
"server"
></
asp:TextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
C#:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
Button Button1 = (Button)sender;
GridEditableItem eitem = (GridEditableItem)Button1.NamingContainer;
DropDownList ddl = (DropDownList)eitem.FindControl(
"DropDown1"
);
TextBox txt1 = (TextBox)eitem.FindControl(
"TextBox1"
);
// your query to get the datafrom db
//access the 4th and 5th textbox and set the text property.
TextBox txt2 = (TextBox)eitem.FindControl(
"TextBox2"
);
TextBox txt3 = (TextBox)eitem.FindControl(
"TextBox3"
);
}
Thanks,
Shinu.
0

Venkatesh
Top achievements
Rank 1
answered on 26 Dec 2012, 02:26 PM
Hi,
Thanks for the reply.
I have done as below:
How to know that the button is clicked in Insertmode or editmode?
Also, how to get the value of the dropdown, when the values are changed?
Is the above code correct?
Thanks
Thanks for the reply.
I have done as below:
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Delete ?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
ConfirmDialogHeight
=
"100px"
ConfirmDialogWidth
=
"220px"
>
</
telerik:GridButtonColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Gender"
DataField
=
"Title"
UniqueName
=
"Title"
Visible
=
"true"
>
<
ItemTemplate
>
<
asp:DropDownList
ID
=
"DropDown1"
runat
=
"server"
SelectedValue='<%# Eval("Gender") %>' />
<
asp:TextBox
ID
=
"userid"
ReadOnly
=
"true"
runat
=
"server"
Text='<%# Eval("Title") %>' />
</
ItemTemplate
>
<
InsertItemTemplate
>
<
asp:DropDownList
ID
=
"DropDown1"
runat
=
"server"
>
<
asp:ListItem
Text
=
"Male"
Value
=
"Male"
></
asp:ListItem
>
<
asp:ListItem
Text
=
"Female"
Value
=
"Female"
></
asp:ListItem
>
</
asp:DropDownList
>
<
asp:TextBox
ID
=
"userid"
runat
=
"server"
></
asp:TextBox
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Button1"
OnClick
=
"Button1_Click"
/>
</
InsertItemTemplate
>
<
EditItemTemplate
>
<
asp:DropDownList
ID
=
"DropDown1"
runat
=
"server"
SelectedValue='<%# Eval("Gender") %>'>
</
asp:DropDownList
>
<
asp:TextBox
ID
=
"userid"
runat
=
"server"
Text='<%# Eval("Title") %>'></
asp:TextBox
>
<
asp:Button
ID
=
"Button1"
runat
=
"server"
Text
=
"Button1"
OnClick
=
"Button1_Click"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"FirstName"
HeaderText
=
"First Name"
UniqueName
=
"FirstName"
Visible
=
"true"
>
<
InsertItemTemplate
>
<
telerik:RadTextBox
ID
=
"RadtxtFirstName"
runat
=
"server"
Text
=
""
>
</
telerik:RadTextBox
>
</
InsertItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadTextBox
ID
=
"RadtxtFirstName"
runat
=
"server"
Text='<%# Eval("FirstName") %>' >
</
telerik:RadTextBox
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
telerik:RadTextBox
ID
=
"RadtxtFirstName"
ReadOnly
=
"true"
runat
=
"server"
Text='<%# Eval("FirstName") %>' />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
How to know that the button is clicked in Insertmode or editmode?
Also, how to get the value of the dropdown, when the values are changed?
Is the above code correct?
Thanks
0
Accepted

Shinu
Top achievements
Rank 2
answered on 27 Dec 2012, 03:34 AM
Hi,
Please try using different Id's for the controls in InsertItemTemplate and EditItemTemplate, so that the Buttons have different Button click events. You can get selected value from the DropDown as follows.
C#:
Regards,
Shinu.
Please try using different Id's for the controls in InsertItemTemplate and EditItemTemplate, so that the Buttons have different Button click events. You can get selected value from the DropDown as follows.
C#:
. . .
GridEditableItem eitem = (GridEditableItem)Button1.NamingContainer;
DropDownList ddl = (DropDownList)eitem.FindControl(
"DropDown1"
);
string
selectedText=ddl.SelectedItem.Text;
string
selectedValue=ddl.SelectedItem.Value;
. . .
Regards,
Shinu.