Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey everyone,

I am using telerik controls with asp.net.I have a RadGrid which i am using only to insert items.Its aspx is
XML
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound"
                    OnItemCreated="RadGrid1_ItemCreated" OnColumnCreated="RadGrid1_ColumnCreated"
                    AllowAutomaticInserts="true" OnNeedDataSource="RadGrid1_NeedDataSource" Skin="Office2007"
                    AutoGenerateColumns="true">
                    <MasterTableView EditMode="InPlace" EnableNoRecordsTemplate="true" EnableViewState="true">
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridTemplateColumn HeaderText="Items" UniqueName="ItemColumn">
                                <ItemTemplate>
                                    <asp:Label ID="lblItemName" runat="server" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:DropDownList ID="ddlItems" runat="server" DataSourceID="SqlDataSource1" AutoPostBack="true" />
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Rate" UniqueName="RateColumn">
                                <ItemTemplate>
                                    <asp:Label ID="lblRate" runat="server" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Quantity" UniqueName="QuantityColumn">
                                <ItemTemplate>
                                    <asp:Label ID="lblQuantity" runat="server" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadTextBox ID="txtQuantity" runat="server" />
                                </EditItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn HeaderText="Amount" UniqueName="AmountColumn">
                                <ItemTemplate>
                                    <asp:Label ID="lblAmount" runat="server" />
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridButtonColumn HeaderText="Done" Text="Done" UniqueName="Donecolumn">
                            </telerik:GridButtonColumn>
                        </Columns>
                        <NoRecordsTemplate>
                            There isn't any data.</NoRecordsTemplate>
                    </MasterTableView>
                    <ClientSettings EnablePostBackOnRowClick="true" />
                </telerik:RadGrid>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataReader"
                ConnectionString="<%$ ConnectionStrings:ChalkHillConnectionString3 %>"
                SelectCommand="SELECT [ProductName] FROM [tblProducts]"></asp:SqlDataSource>



And CS is
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RadGrid1.Visible = true;
            }
        }

        protected void btnHome_Click(object sender, EventArgs e)
        {
            Response.Redirect("Home.aspx");
        }
        protected void ddlItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddlItems = (DropDownList)sender;
            GridEditFormItem editItem = (GridEditFormItem)ddlItems.NamingContainer;
            GridDataItem item = (GridDataItem)editItem.ParentItem; // access GridDataItem
            Label lblRate = (Label)item.FindControl("lblRate"); // access Label using DataItem
            if (ddlItems.SelectedIndex > 0)
            {
                DataSet ds = objSQLHelper.GetProductDetails("select * from tblProducts where Pid=" + ddlItems.SelectedValue);
                if (ds != null)
                {
                    lblRate.Text = ds.Tables[0].Rows[0]["Rate"].ToString();
                }
            }
        }

        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))
            {
                GridEditFormItem editform = (GridEditFormItem)e.Item;
                e.Item.Edit = true;
                DropDownList ddlItems = (DropDownList)editform.FindControl("ddlItems");
                ddlItems.DataSource = SqlDataSource1;
                ddlItems.DataTextField = "ProductName";
                ddlItems.DataValueField = "Pid";
                ddlItems.DataBind();
            }
        }
        private void RadGrid1_PreRender(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                foreach (GridItem item in RadGrid1.MasterTableView.Items)
                {
                    if (item is GridEditableItem)
                    {
                        GridEditableItem editableItem = item as GridDataItem;
                        editableItem.Edit = true;
                    }
                }
                RadGrid1.Rebind();
            }
        }
        protected void RadGrid1_ItemCreated(object sender, EventArgs e)
        {

        }
        protected void RadGrid1_ColumnCreated(object sender, EventArgs e)
        {

        }
        protected void RadGrid1_NeedDataSource(object sender, EventArgs e)
        {

        }
        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "RowClick")
            {
                RadAjaxManager manager = RadAjaxManager.GetCurrent(this.Page);
                manager.Alert("Row was clicked!");
                this.RadGrid1.DataSource = new object[] { };
                this.RadGrid1.DataBind();

            }
        }

And what i get is nothing.Why is grid not visible?...
Posted
Updated 7-Oct-10 19:37pm
v2

protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IspostBack)
{
RadGrid1.DataSource = //datasource;
RadGrid1.DataBind();
}

}
 
Share this answer
 
Comments
AmitChoudhary10 8-Oct-10 1:52am    
I need to show an empty grid which will be used for inserting records.than the records within table would be saved to the database.I am takin dataset ds as datasouce but that also does'nt work..
m@dhu 8-Oct-10 2:00am    
If the dataset is empty obviously the grid will be empty and
without binding the grid how can the grid be visible?
AmitChoudhary10 8-Oct-10 2:47am    
Than what to do?...I have to show the grid empty in edited mode.
m@dhu 8-Oct-10 4:57am    
May not be the best, Clear the dataset in the edit mode which makes grid empty.
Do you really need below block?
C#
protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RadGrid1.Visible = true;
            }
        }

Remove the line
RadGrid1.Visible = true;

from Page_Load()

Also check while debugging can you able to data in the dataset?
 
Share this answer
 
Comments
AmitChoudhary10 8-Oct-10 1:54am    
I need to show an empty grid which will be used for inserting records.than the records within table would be saved to the database.So there will be no data Item initially in the grid.removed RadGrid1.Visible = true;.still not visible.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900