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

Edit Button doesn't show Edit Form in RadGrid

1 Answer 253 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jennifer
Top achievements
Rank 1
Jennifer asked on 27 Oct 2011, 08:02 PM

I have the search form and RadGrid on the same page. I'm databinding the RadGrid using the button click in the codebehind. The search works, but when I click an Edit button in a row, the RadGrid disappears. If I click my search forms button again, the RadGrid reappears with the correct row in Edit Mode.

I think I'm missing data binding the RadGrid to an additional event handler, but I'm not sure. I've tried several events and it didn't change.

Here's my super-simplified code.
ASPX

 

 

<telerik:radscriptmanager runat="server"></telerik:radscriptmanager>

 

Column Name:

<asp:DropDownList ID="DropDownList1" runat="server">

 

 

<asp:ListItem Value="PROD_DIET_SUPP_NAME">Product Name</asp:ListItem>

 

 

<asp:ListItem Value="PRODUCT_CODE">Product Code</asp:ListItem>

 

 

<asp:ListItem></asp:ListItem>

 

 

</asp:DropDownList>

 

 

Function:

<asp:DropDownList ID="DropDownList4" runat="server">

 

 

<asp:ListItem Value="Contains">Contains</asp:ListItem>

 

 

<asp:ListItem Value="StartsWith">Starts With</asp:ListItem>

 

 

<asp:ListItem></asp:ListItem>

 

 

</asp:DropDownList>

 

 

Search Term:

 

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />

 

 

 

<asp:Button ID="Button1"

 

 

runat="server" Text="Search" onclick="Button1_Click" />

 

 

 

<telerik:RadGrid ID="RadGrid1" runat="server"

 

 

AllowSorting="True"

 

 

AllowAutomaticDeletes="True"

 

 

AllowAutomaticInserts="True"

 

 

AllowAutomaticUpdates="True"

 

 

EditMode="EditForms"

 

 

GridLines="None"

 

 

AutoGenerateColumns="False"

 

 

>

 

 

<MasterTableView

 

 

DataKeyNames="PRODUCT_CODE"

 

 

CommandItemDisplay="TopAndBottom">

 

 

<norecordstemplate>

 

No products have been entered matching your search crieteria. Try removing one of more keywords from your search and try again.

</norecordstemplate>

 

 

<Columns>

 

 

 

<telerik:GridEditCommandColumn UniqueName="EditCommandColumn"

 

 

ButtonType="imagebutton" />

 

 

 

<telerik:GridBoundColumn

 

 

DataField="PRODUCT_CODE"

 

 

DataType="System.Char"

 

 

HeaderText="Product Code"

 

 

ReadOnly="True"

 

 

SortExpression="PRODUCT_CODE"

 

 

UniqueName="PRODUCT_CODE" />

 

 

 

<telerik:GridBoundColumn EditFormColumnIndex="0"

 

 

DataField="PROD_DIET_SUPP_NAME" HeaderText="Name"

 

 

SortExpression="PROD_DIET_SUPP_NAME"

 

 

UniqueName="PROD_DIET_SUPP_NAME" />

 

 

 

 

</Columns>

 

<

 

EditFormSettings ColumnNumber="1" CaptionFormatString="Edit details for {0}" CaptionDataField="PROD_DIET_SUPP_NAME">

 

</

 

EditFormSettings>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 

 

 



CODEBEHIND

 

public

 

partial class search4 : System.Web.UI.Page

 

{

 

protected void Page_Load(object sender, EventArgs e)

 

{

}

 

protected void BindData()

 

{

 

 

DataClassesDataContext dc = new DataClassesDataContext();

 

 

string strWhere = "1=1";

 

 

string strKeyword = "";

 

 

string strColumn = "";

 

 

string strFunction = "";

 

strKeyword = TextBox1.Text;

strColumn = DropDownList1.SelectedValue;

strFunction = DropDownList4.SelectedValue;

 

string strOrderBy = "PROD_DIET_SUPP_NAME ASC";

 

 

if (!string.IsNullOrEmpty(TextBox1.Text))

 

{ strWhere = strColumn +

"." + strFunction + "(\"" + strKeyword + "\")"; }

 

 

var products = from m in (dc.PRODUCTs.Where(strWhere)

 

)

 

select new { m.PRODUCT_CODE, m.FORM_CODE, m.PROD_DOSAGE_CODE, m.PROD_DIET_SUPP_NAME, m.PROD_TYPE_CODE, m.SOURCE_PROD_CODE, m.PROD_PROD_INF_NOTES, m.PROD_IS_VERIFIED, m.PRODUCT_STATUS, m.LAST_VERIFIED_DATE, m.PROD_VERSION_CREATED, m.PROD_VERSION_NO, m.PROD_GENERIC_PROD, m.DATE_OF_RECIPT };

 

products = products.OrderBy(strOrderBy);

RadGrid1.DataSource = products;

RadGrid1.DataBind();

 

}

 

protected void Button1_Click(object sender, EventArgs e)

 

{

BindData();

}

 

}

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 28 Oct 2011, 04:22 AM
Hello Jennifer,

In order to implement advanced features in RadGrid like paging, editing, sorting etc you should use Advanced data binding using NeedDataSource event which fires each time when any of these operation occurs. Check the following help documentation which explains more about this.
Advanced Data-binding (using NeedDataSource event).

Thanks,
Shinu.
Tags
Grid
Asked by
Jennifer
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or