I'm trying to load treelist, everything works well but i always see "No Records To Display".
Here is the control:
<telerik:RadTreeList ID="trlProductGroups" runat="server" AllowPaging="true" PageSize="5"
DataKeyNames="ID" ParentDataKeyNames="PARENT_ID" AutoGenerateColumns="false"
OnInsertCommand="trlProductGroups_InsertCommand" OnNeedDataSource="trlProductGroups_NeedDataSource"
OnUpdateCommand="trlProductGroups_UpdateCommand" OnDeleteCommand="trlProductGroups_DeleteCommand">
<Columns>
<telerik:TreeListEditCommandColumn UniqueName="InsertCommandColumn" ButtonType="ImageButton"
HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center" />
<telerik:TreeListEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton">
<ItemStyle CssClass="MyImageButton" />
</telerik:TreeListEditCommandColumn>
<telerik:TreeListButtonColumn UniqueName="DeleteCommandColumn" Text="Delete" CommandName="Delete"
ButtonType="ImageButton" />
<telerik:TreeListBoundColumn DataField="ID" UniqueName="ID" HeaderText="Grup ID"
ReadOnly="true" />
<%-- <telerik:TreeListTemplateColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME" HeaderText="Grup Adı">
<EditItemTemplate>
<asp:TextBox ID="txtGroupName" runat="server"></asp:TextBox>
</EditItemTemplate>
</telerik:TreeListTemplateColumn>--%>
<telerik:TreeListBoundColumn DataField="GROUP_NAME" UniqueName="GROUP_NAME" HeaderText="Grup Adı" />
<telerik:TreeListBoundColumn DataField="PARENT_ID" UniqueName="PARENT_ID" HeaderText="Ana Grup ID"
ReadOnly="true" />
</Columns>
</telerik:RadTreeList>
And here is the NeedDataSource Code:
protected void trlProductGroups_NeedDataSource(object sender, TreeListNeedDataSourceEventArgs e)
{
WebAppTest.Objects.ProductGroups pGroups = new WebAppTest.Objects.ProductGroups();
DataTable dt = pGroups.SelectData(null, string.Empty);
trlProductGroups.DataSource = dt;
}
I can see the data in DataTable, but treelist wont load data. Is there any mistake i make?
Thanks
It's needs to be, at least one data has null id_parent value in datasoruce. Maybe it helps.
Related
I have added a button for Print in my gridview table as follows
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource2"
onselectedindexchanged="GridView1_SelectedIndexChanged" Width="522px">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Story_number" HeaderText="Story_number"
SortExpression="Story_number" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
<asp:BoundField DataField="Memory_card" HeaderText="Memory_card"
SortExpression="Memory_card" />
<asp:BoundField DataField="Story_Name" HeaderText="Story_Name"
SortExpression="Story_Name" />
<asp:ButtonField ButtonType="Button" Text="print" />
</Columns>
</asp:GridView>
Please help me with the c# code for this button. When the button is pressed I need it to redirect to a page (print.aspx). I have been trying the following code but it does not work .Thanks in advance for your help.
Session["id"] = GridView1.SelectedRow.Cells[0].Text;
Response.Redirect("Print.aspx");
Instead of buttonField, use template field
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="ButtonPrint" runat="server" CssClass="yourCssClassIsNeedIt" OnClick="printRegFunction"
CommandArgument='<%# Bind("id") %>' ImageUrl="images/button.png"/>
</ItemTemplate>
</asp:TemplateField>
your server code or behind code here:
protected void printRegFunction(object sender, ImageClickEventArgs e)
{
Session["id"] = ((ImageButton)sender).CommandArgument;
Response.Redirect("Print.aspx");
}
Relative newbie here. Discovered that I have to write an event handler to handle sorting of my data from an objectdatasource. Found a lot of references to code like what's below, but when the code runs I get the message "Cannot find column xxx" where xxx is the name of the column I'm trying to sort on.
I've verified that e.SortExpression is returning the proper column name, but the problem appears to be in the 2nd line below, where I try to create a datatable (dt) from the GridView1.Datasource. The value of dt after this statement is 'nothing', so the rest of the code fails.
Also, I'm listing most of the gridview definition in case that's helpful.
Protected Sub GridView1_Sorting(sender As Object, e As GridViewSortEventArgs) Handles GridView1.Sorting
Dim dt As Data.DataTable = New Data.DataTable(GridView1.DataSource)
If Not dt Is Nothing Then
dt.DefaultView.Sort = e.SortExpression
GridView1.DataSource = dt
GridView1.DataBind()
End If
End Sub
ASPX snippet:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" CellPadding="4"
EmptyDataText="No records found for your search" ForeColor="#333333"
GridLines="None" Width="930px" BorderColor="#CCCCCC" Font-Size="12px" AllowSorting="True">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="CustName" HeaderText="CustName"
SortExpression="CustName" />
<asp:BoundField DataField="CustType" HeaderText="CustType"
SortExpression="CustType" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center" />
<asp:TemplateField HeaderText="Address" SortExpression="Addr1">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Addr1") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Addr1") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" />
<asp:BoundField DataField="ContactName" HeaderText="ContactName"
SortExpression="ContactName" />
<asp:BoundField DataField="LastContactDate" HeaderText="LastContact" SortExpression="LastContactDate" dataformatstring="{0:d}" />
<asp:BoundField DataField="CustSince" HeaderText="CustSince"
SortExpression="CustSince" dataformatstring="{0:MM/dd/yyyy}" />
<asp:BoundField DataField="Status" HeaderText="Status"
SortExpression="Status" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" />
<asp:BoundField DataField="Source" HeaderText="Source"
SortExpression="Source" />
<asp:BoundField DataField="RelMgr" HeaderText="RelMgr"
SortExpression="RelMgr" />
<asp:TemplateField HeaderText="RelMgrInfo">
<ItemTemplate>
<asp:HyperLink ID="RelMgrEmailLink" runat="server" NavigateUrl='<%#Eval("RelMgrEmail", "mailto:{0}")%>' Text='<%# Eval("RelMgrEmail") + "<br>" + Eval("RelMgrPhone")%> '> </asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>
Thanks!
You don't have to handle the sorting event if you work with the ObjectDataSource. Instead, set the SortParameterName to a string (like "OrderBy") and augment your business method signature that ObjectDataSource uses to retrieve data with this parameter:
public IEnumerable<Whatever> Retrieve( string OrderBy, ... other arguments ) ...
The grid will pass the parameter value to the ODS and then ODS will pass it to your method.
i have a grid view inside update panel with multiple bound fields the last two bound field as shown in image when click show another grid view without post back but download not working except i set EnablePartialRendering="false" of script-manager
but in this case updatepanel not working to show bound field
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<contenttemplate>
<div id="DivImages" runat="server" visible="false" class="block rnd">
<div class="title2">الأحكـــــــــــام</div>
<div class="content2">
<asp:gridview ID="GvImages" runat="server" PagerStyle-CssClass="pages" AllowPaging="True"
AutoGenerateColumns="False" CellSpacing="-1" Width="100%" DataKeyNames="DocCode,IssuesID"
CssClass="dataGrid" OnPageIndexChanging="GvImages_PageIndexChanging" GridLines="None"
PageSize="20" OnRowCommand="GvImages_RowCommand"
OnSelectedIndexChanging="GvImages_SelectedIndexChanging">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="رقم السجــل">
<ItemTemplate>
<%# Container.DataItemIndex + 1 %>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DocCode" HeaderText="رقم الحكم/ القرار" SortExpression="DocCode" />
<asp:BoundField DataField="IssuesNum" HeaderText="كود القضيه"
SortExpression="IssuesNum" />
<asp:BoundField DataField="TypeName" HeaderText="نوع القضيه"
SortExpression="TypeName" />
<asp:BoundField DataField="Year" HeaderText="السنه"
SortExpression="Year" />
<asp:BoundField DataField="Area" HeaderText="المنطقه"
SortExpression="Area" />
<asp:BoundField DataField="DocTypeName" HeaderText="تصنيــف المستند" SortExpression="DocTypeName" />
<asp:BoundField DataField="Name" HeaderText="نوع المستند"
SortExpression="Name" />
<asp:TemplateField HeaderText="حذف">
<ItemTemplate>
<asp:LinkButton ID="cmd_DeleteRow" CommandName="DeleteRow" CssClass="delete" ToolTip="حذف" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" runat="server" OnClientClick="return confirmDeleteRow()" />
</ItemTemplate>
<HeaderStyle Width="125px" />
</asp:TemplateField>
<asp:CommandField SelectText="عرض" HeaderText="عرض" ShowHeader="True" ShowSelectButton="True">
<HeaderStyle HorizontalAlign="Right" />
</asp:CommandField>
<asp:TemplateField HeaderText="تحميل">
<ItemTemplate>
<asp:LinkButton ID="DownLoad" CommandName="DownLoad" Text="تحميل" ToolTip="تحميل" CommandArgument="<%# ((GridViewRow)Container).RowIndex %>" runat="server" />
</ItemTemplate>
<HeaderStyle Width="125px" />
</asp:TemplateField>
</Columns>
<RowStyle Height="25px" />
<HeaderStyle Height="30px" />
<PagerStyle CssClass="pages" Wrap="false" />
</asp:gridview>
</div>
</div>
</contenttemplate>
<Triggers>
in button search i bind my grid
like in this code
protected void ShowDoc(string sCondition)
{
//declare connection by pass connection string from web.config
SqlConnection sqlcon = new SqlConnection
(ConfigurationManager.ConnectionStrings["SystemConn"].ConnectionString);
//declare sql statment as astring variable
if (Session["Image"] != null)
{
Session.Remove("Image");
}
try
{
SqlStatment = string.Format("select distinct IssuesNum,DocType,DocTypeSub,DocCode,DocTypeName,Name,IssuesID,TypeID,TypeName,Area,IssuesNumSplited,Year from [View_ImagesSearch] Where {0} Order By [IssuesNumSplited] ASC", sCondition);
//create asql command and pass for it the connection string and sql statment
SqlCommand sqlcom = new SqlCommand(SqlStatment, sqlcon);
//create data adaptor to bring data from database
SqlDataAdapter sad = new SqlDataAdapter(sqlcom);
// declare dataset to store data from data base in it
DataSet ds = new DataSet();
//fill data set with data adabter that contain data from database
sad.Fill(ds);
lblDocCount2.Text = ds.Tables[0].Rows.Count.ToString();
Session["Image"] = ds;
GvImages.DataSource = ds;
GvImages.DataBind();
}
catch (Exception ex)
{
par_ErrorMessage.Visible = true;
par_ErrorMessage.InnerText = ex.Message;
}
}
when i click command called عرض updatepanel work to show another gridview
but when iclick item template download not workink fine untill i set EnablePartialRendering="False"
Make sure you are calling Update on the UpdatePanel after you call DataBind on the GridView:
GridView.DataBind();
UpdatePanel.Update();
See this for other possible solutions.
Hello I'm doing a school project and I'm stuck on a problem any help would be great
i have a Shopping Cart Gridview that has a text box quantity where a user can change quantity value for some reason it is not getting the new value just the old value thank you!
<div class="container">
<h1>Shopping Cart</h1>
< Back to Products
<br /><br />
<asp:Label ID="Label2" runat="server" ></asp:Label>
<asp:Label ID="Label3" runat="server" ></asp:Label>
<asp:GridView runat="server" ID="gvShoppingCart" AutoGenerateColumns="false" EmptyDataText="There is nothing in your shopping cart." GridLines="None" Width="100%" CellPadding="5" ShowFooter="true" DataKeyNames="ProductID" OnRowDataBound="gvShoppingCart_RowDataBound" OnRowDeleting="grdCart_RowDeleting" >
<HeaderStyle HorizontalAlign="Left" BackColor="#3D7169" ForeColor="#FFFFFF" />
<FooterStyle HorizontalAlign="Right" BackColor="#6C6B66" ForeColor="#FFFFFF" />
<AlternatingRowStyle BackColor="#F8F8F8" />
<Columns>
<asp:BoundField DataField="ProductName" HeaderText="Brand" />
<asp:TemplateField HeaderText="Quantity">
<ItemTemplate>
<asp:TextBox runat="server" ID="txtQuantity" Columns="5" Text='<%# Eval("Quantity") %>'></asp:TextBox><br />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Price" HeaderText="Price" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
<asp:BoundField DataField="SubTotal" HeaderText="Total" ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Right" DataFormatString="{0:C}" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
<br />
<asp:Button runat="server" ID="btnUpdateCart" Text="Update Cart" OnClick="btnUpdateCart_Click" /><br />
<asp:Button ID="btnClose2" runat="server" Text="Close" Width="50px" />
</div>
The code behind
protected void btnUpdateCart_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gvShoppingCart.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
// We'll use a try catch block in case something other than a number is typed in
// If so, we'll just ignore it.
try
{
// Get the productId from the GridView's datakeys
int productId = Convert.ToInt32(gvShoppingCart.DataKeys[row.RowIndex].Value);
Label2.Text = productId.ToString();
// Find the quantity TextBox and retrieve the value
int quantity = int.Parse(((TextBox)row.Cells[1].FindControl("txtQuantity")).Text);
Label3.Text = quantity.ToString();
ShoppingCart.Cart.Instance.SetItemQuantity(productId, quantity);
BindData();
}
catch (FormatException) { }
}
}
mpe2.Show();
}
I assume that you're databinding the GridView also on postbacks. You should do that only when !Page.IsPostBack:
if(!IsPostBack) BindGrid();
Apart from that, if you use a TemplateField, you should use FindControl to get a reference to your control:
var txtQuantity = (TextBox)row.FindControl("txtQuantity");
int quantity = int.Parse(txtQuantity.Text);
Sidenote: You dont need to check for DataControlRowType.DataRow when iterating the GridView rows(unlike in RowCreated or RowDataBound).
As my gridview is populating I want to add an extra column with some buttons in but I can't seem to figure out how, or what might be the best way. Can anyone get me started?
Use a Template Column
<asp:GridView ID="GridView1" runat="server" DataKeyNames="id" DataSourceID="SqlDataSource1"
OnRowCommand="GridView1_OnRowCommand">
<Columns>
<asp:BoundField DataField="name" HeaderText="Name" />
<asp:BoundField DataField="email" HeaderText="Email" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="SendMail"
Text="SendMail" CommandArgument='<%# Eval("id") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName != "SendMail") return;
int id = Convert.ToInt32(e.CommandArgument);
// do something
}