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

creating RadGrdid from codebehind

0 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ravi Prasad Potturi
Top achievements
Rank 1
Ravi Prasad Potturi asked on 11 Sep 2008, 01:24 AM
Hi,
 
                I  created grid dynamically and paced button on page.It is working fine except column width when i browse the page first time.
                I am also  displaying seach conditions in RadWindow when user clicks on button.

Note : I created xml file for columns definations and using to generate the bound columns.

Below is my code for HTML,codebehind, xml and xml helper functions.

Can you please help me to resolve the below issues?

Issues List :
               1. I am getting extra columns when i click on pager to selct particular page or  column for sort.
               2. I want to sort the records within the page not on data source, Is there any way we can sort the records present in the page?
              3. How can we set the column width in RadGrid?
              4. I am getting the popup with retry and cancel buttons with the below message when i seach the records other than first page or before selecting the column sort or paging. Can you please advice me on this?
  
To Display the webpage again, Internet Explorer needs to resend the information you've previously submited

If you were making a purchase, you should click Cancel to avoid a duplicate transaction. Otherwise, click Retry to display the webpage again.


HTML :

<%

@ Page Language="C#" MasterPageFile="~/DealerFinance.master" AutoEventWireup="true" CodeFile="DealerList.aspx.cs" Inherits="Dealer_DealerList" Title="Untitled Page" %>

<%

@ MasterType VirtualPath="~/DealerFinance.master" %>

<%

@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<

asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

</

asp:Content>

<

asp:Content ID="Content2" ContentPlaceHolderID="DealerFinancePlaceHolder" Runat="Server">

<table>

<tr>

<td align="left">

<asp:Button ID="btnSearch" runat="server" CausesValidation="false" SkinID="DisplayButton"

Text="Search" />

&nbsp;

</td>

</tr>

<tr>

<td>

<telerik:RadGrid ID="grdDealerList" runat="server" >

</telerik:RadGrid>

</td>

</tr>

</table>

<telerik:radwindow openerelementid="<%# btnSearch.ClientID %>" navigateurl="DealersSearch.aspx"

runat="server" width="400px" height="350px" id="Radwindow4" visiblestatusbar="false"

skin="Mac"></telerik:radwindow>

</

asp:Content>

ASPX :

using

System;

using

System.Collections;

using

System.Configuration;

using

System.Data;

using

System.Linq;

using

System.Web;

using

System.Web.Security;

using

System.Web.UI;

using

System.Web.UI.HtmlControls;

using

System.Web.UI.WebControls;

using

System.Web.UI.WebControls.WebParts;

using

System.Xml.Linq;

using

Telerik.Web.UI;

using

System.Data.SqlClient;

using

System.Xml;

public

partial class Dealer_DealerList : System.Web.UI.Page

{

public string searchCondition = "";

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

Master.SelectedDealerTab = 1;

DealSearchFields dealerSeachFieldsObj = (DealSearchFields)Session["DealerSearchFields"];

if (dealerSeachFieldsObj != null)

{

searchCondition = dealerSeachFieldsObj.DealerNumber;

}

else

{

searchCondition =

"";

}

}

 

}

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)

{

grdDealerList.DataSource = BindGrid();

}

private DataTable BindGrid()

{

string sql = "SELECT ROW_ID ,DEALER_NUM ,NAME, LEGAL_NAME, SALES_DISTRICT, BUSINESS_TYPE FROM KF_DEALER where DEALER_NUM LIKE '%" + searchCondition + "%' order by DEALER_NUM";

SqlDataAdapter adapter = new SqlDataAdapter(sql,

ConfigurationManager.ConnectionStrings["KC_DealerFinanceConnectionString"].ConnectionString);

DataTable dt = new DataTable();

adapter.Fill(dt);

return dt;

}

protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)

{

if (e.CommandName == "Select")

{

GridDataItem dataItem = (GridDataItem)e.Item;

string strTxt = dataItem.GetDataKeyValue("DEALER_NUM").ToString();

string rowID = dataItem.GetDataKeyValue("ROW_ID").ToString();

Response.Redirect(

"DealerDetails.aspx");

}

 

 

}

protected void Page_Init(object sender, System.EventArgs e)

{

DefineGridStructure();

}

 

private void DefineGridStructure()

{

//RadGrid grdDealerList = new RadGrid();

//grdDealerList.ID = "RadGrid1";

grdDealerList.NeedDataSource +=

new GridNeedDataSourceEventHandler(this.RadGrid1_NeedDataSource);

grdDealerList.ItemCommand +=

new GridCommandEventHandler(this.RadGrid1_ItemCommand);

//grdDealerList.DataSource = BindGrid();

grdDealerList.Skin =

"Inox";

//grdDealerList.Width = Unit.Percentage(100);

grdDealerList.PageSize = 5;

grdDealerList.AllowPaging =

true;

grdDealerList.PagerStyle.Mode =

GridPagerMode.NextPrevAndNumeric;

grdDealerList.AutoGenerateColumns =

false;

//grdDealerList.GroupingEnabled = true;

//grdDealerList.ShowGroupPanel = true;

grdDealerList.ShowStatusBar =

true;

grdDealerList.ClientSettings.AllowDragToGroup =

true;

grdDealerList.AllowSorting =

true;

grdDealerList.Width =

Unit.Percentage(100);

 

grdDealerList.MasterTableView.PageSize = 15;

grdDealerList.MasterTableView.DataKeyNames =

new string[] { "ROW_ID", "DEALER_NUM" };

GridButtonColumn selectColumn = new GridButtonColumn();

selectColumn.DataTextField =

"DEALER_NUM";

selectColumn.CommandArgument =

"DEALER_NUM";

selectColumn.CommandName =

"Select";

selectColumn.HeaderText =

"DealerNumber";

//selectColumn.

grdDealerList.MasterTableView.Columns.Add(selectColumn);

 

XmlDocument xmlDoc = new XmlDocument();

xmlDoc.Load(Request.MapPath(

"~/App_Data/DataMapping.xml"));

XmlNodeList columnNodeList = XML.GetNodeList("/DealerGrids/DealerGrid[@Name ='DealerList']/Columns/Column", xmlDoc);

 

foreach (XmlNode columnNode in columnNodeList)

{

string headerText = "";

headerText =

XML.GetAttributeValue("/Column", "DisplayText", columnNode.OuterXml);

if (headerText != null && headerText.Length > 0)

{

GridBoundColumn boundColumn = new GridBoundColumn();

boundColumn.DataField =

XML.GetAttributeValue("/Column", "TableColumnName", columnNode.OuterXml);

boundColumn.HeaderText = headerText;

grdDealerList.MasterTableView.Columns.Add(boundColumn);

}

}

this.PlaceHolder1.Controls.Add(grdDealerList);

}

}

XML :

<

DealerGrids>

<

DealerGrid Name="DealerList">

<

Columns>

<

Column TableColumnName="ROW_ID" DisplayText="" isDataKey="true" />

<

Column TableColumnName="DEALER_NUM" DisplayText="Dealer Number" isDataKey="true" />

<

Column TableColumnName="NAME" DisplayText="Dealer Name" isDataKey="true" />

<

Column TableColumnName="LEGAL_NAME" DisplayText="Legal Name" isDataKey="false" />

<

Column TableColumnName="SALES_DISTRICT" DisplayText="District" isDataKey="false" />

<

Column TableColumnName="BUSINESS_TYPE" DisplayText="Business Type" isDataKey="false" />

</

Columns>

</

DealerGrid>

</

DealerGrids>


XML Helper Methods :

public

static string GetAttributeValue (string xPath, string attribute, XmlDocument xmlDocument)

{

XmlElement eleNode = null;

XmlAttribute atrNode = null;

eleNode = (XmlElement)xmlDocument.SelectSingleNode(xPath);

atrNode = (XmlAttribute)eleNode.Attributes.GetNamedItem(attribute);

if (null == atrNode)

{

return "";

}

else

{

return atrNode.Value;

}

}

public

static XmlNodeList GetNodeList (string xPath, XmlDocument xmlDocument)

{

if (0 == xPath.Length || null == xmlDocument)

{

return null;

}

XmlNodeList nodeList = null;

nodeList = xmlDocument.SelectNodes(xPath);

if(0 == nodeList.Count)

{

return null;

}

else

{

return nodeList;

}

}




             

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Ravi Prasad Potturi
Top achievements
Rank 1
Share this question
or