Telerik Forums
UI for ASP.NET AJAX Forum
1 answer
86 views
Hi team,
My radgrid has its auto genereate column set to true. And I have a serial number column in it.
I want to hide filter for serial number column only and want rest of columns to retain filters. Please help in acheiving this features.
I am attaching gridview for your reference.
<telerik:RadGrid ID="gvPreview" AutoGenerateColumns="true" AllowPaging="True" PageSize="10"
                             runat="server" GridLines="vertical" Width="99%" AllowSorting="true" OnPreRender="gvPreview_PreRender"
                            Font-Bold="true" EnableViewState="true"
                             EnableTheming="false" Height="380px" AllowFilteringByColumn="true" OnPageIndexChanged="gvPreview_PageIndexChanged"
                             OnNeedDataSource="gvPreview_NeedDataSource" OnPageSizeChanged="gvPreview_PageSizeChanged">
                             <ExportSettings HideStructureColumns="true" IgnorePaging="true" OpenInNewWindow="true"
                                 ExportOnlyData="true">
                             </ExportSettings>
                             <GroupingSettings CaseSensitive="false" />
                           <ItemStyle CssClass="grid-content-Maintext" HorizontalAlign="Left" ForeColor="Black"
                     VerticalAlign="Middle" BackColor="#f4fdff"></ItemStyle>
                 <AlternatingItemStyle CssClass="grid-content-Alttext" HorizontalAlign="Left" ForeColor="Black"
                     VerticalAlign="Top" BackColor="White" />
                 <HeaderStyle CssClass="background_dbf7ff lineHeight_25px" Font-Bold="True"
                     HorizontalAlign="Left" Wrap="true" ForeColor="Black" VerticalAlign="Middle"
                     BackColor="#f4fdff"  Font-Names="Arial" Font-Size="11px" />
                 <PagerStyle CssClass="background_dbf7ff lineHeight_25px" />
                 <SelectedItemStyle CssClass="background_dbf7ff lineHeight_25px" />
                 <GroupHeaderItemStyle CssClass="background_dbf7ff lineHeight_25px" />
                 <ActiveItemStyle CssClass="background_dbf7ff lineHeight_25px" />
                 <CommandItemStyle CssClass="background_dbf7ff lineHeight_25px" />
                 <SortingSettings EnableSkinSortStyles="False" />
                 <FilterItemStyle BackColor="#DBF7FF"  BorderStyle="Solid" />
                 <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" />  
 
 
 
                             <MasterTableView Width="100%" CommandItemDisplay="Top" CommandItemStyle-HorizontalAlign="Right">
                                 <PagerStyle Mode="NextPrevAndNumeric" />
                                 <CommandItemSettings ShowExportToExcelButton="true" ShowAddNewRecordButton="false"
                                     ShowRefreshButton="false" />
                             </MasterTableView>
                             <ClientSettings AllowDragToGroup="true" AllowColumnsReorder="true" ReorderColumnsOnClient="true"
                                 ColumnsReorderMethod="Reorder">
                                  
                                 <Animation AllowColumnReorderAnimation="true" AllowColumnRevertAnimation="true" />
                                 <Scrolling AllowScroll="True" UseStaticHeaders="True" SaveScrollPosition="True">
                                 </Scrolling>
                             </ClientSettings>
                             <PagerStyle AlwaysVisible="true"></PagerStyle>
                         </telerik:RadGrid>


Thanks,
Abhishek
Pavlina
Telerik team
 answered on 25 Apr 2011
1 answer
86 views
Using the tabstrip, I'm wondering whether clicking on a different tab can cause postback?

The datasource is our site map.

The reason is on one tab if the user has partially entered something we want to save this into session variable and load it on the new page.

Ideally clicking any tab would cause a postback, i would save their data, determine where they want to go, possibly do more validation and then redirect to the new tab/page.

thx
Cori
Top achievements
Rank 2
 answered on 25 Apr 2011
1 answer
99 views
I'm trying to generate images at run time and display them in the header row.  I'm trying to do this programatically in the code behind.  I can only seem to display text in the header row.  Both the number of rows and the number of columns are determined at run time. Is there a way I can insert binary image data directly into the header?
Vasil
Telerik team
 answered on 25 Apr 2011
1 answer
83 views

I have a RadGrid, very similar in structure to this one:

http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/comboingrid/defaultcs.aspx?product=combobox

With the grid above, if you click on Edit you can see the status bar showing loading and the grid is always visible.

However, on my RadGrid whenever I click on Add, Edit or Update (when in edit mode) the grid disappears momentarily and then re-appears. The functions are all correct, it goes in and out of edit mode correctly and saves to the database where appropriate, it is just a bit disconcerting for the user that the grid disappears between functions.

Any advice would be greatly appreciated!

Vasil
Telerik team
 answered on 25 Apr 2011
11 answers
572 views
I have Rad Grid with template column(and an image inside), and i want that the width of this column be constant(in pixels).
I add this code-
protected void rgBase_PreRender(object sender, EventArgs e)
     {
         foreach (GridColumn col in rgBase.MasterTableView.RenderColumns)
         {
             if (col.UniqueName == "img_add")
             {
                 col.ItemStyle.Width = Unit.Pixel(20);
                 col.HeaderStyle.Width = Unit.Pixel(20);
             }
 
         }
     }

And it`s show fine on first page load, i also have grid width="100%", and when i resizing window my column "img_add" changing width,  i want that it`s width will be constant and on resizing window. How can i do this?

Andrey
Pavlina
Telerik team
 answered on 25 Apr 2011
3 answers
53 views
Hi,

I'm using a radcombobox within a edititemtemplate and I would like to get the selected item on the client side but no matter which technique I use I always recieve "Object expected error" or "Microsoft JScript runtime error: radcombobox1 is undefined". I'm new
to rad controls I've spent all day on this , I must be doing something wrong. Can you help?

Thanks,
Shinu
Top achievements
Rank 2
 answered on 25 Apr 2011
5 answers
97 views
I have link buttons at

 

 

 

 

<CommandItemTemplate>

 

 

 

 

 

 

 

 

<table width="35%">

 

 

 

 

 

 

 

 

<tr>

 

 

 

 

 

 

 

 

<td><asp:LinkButton ID="ButtonEditAll" runat="server" Text="Edit All"

 

 

 

CommandName="EditAll" /></td>

 

 

 

 

 

 

 

 

<td><asp:LinkButton ID="ButtonUpdateAll" runat="server" Text="Update All"

 

 

 

CommandName="UpdateAll" /></td>

 

 

 

 

 

 

 

 

<td>

 

 

 

 

 

 

 

 

<asp:LinkButton ID="DownloadPDF" runat="server" Text="Download"

 

 

 

CommandName="ExportToPdf" /></td>

 

 

 

 

 

 

 

 

</tr>

 

 

 

 

 

 

 

 

</table>

 

 

 

 

 

 

 

 

</CommandItemTemplate>

 

 

 

 

and I waht to check spelling after clicking this button. But I don't know how to get these buttons client ids.  Please give me a help.

Thanks

Mira
Telerik team
 answered on 25 Apr 2011
1 answer
64 views

hi,

i want to use images from web in my rad editor. Currently Rad editor provides image manager functionality which allows us to use images from local system only. i want to know is there any method by which i can use web images (by giving web URL of images). Due to business requirement i can't use HTML mode of the RAD Editor, so can't inject images through HTML.

Please suggest a solution.

Raghav

Rumen
Telerik team
 answered on 25 Apr 2011
2 answers
44 views
Hi -

Im new to telerik controls.
Im working with the Grid control and have a question regarding master/detail.

There is a black arrow > in each master record line when running the Grid.
Clicking on master records with no details in database displays the "no record" message.
If there was a detail record in the database, it would have been displayed. Working ok.

But is is possible to hide the > arrow on master records that dont have any detail records present?

Second, Hiow do I enable images to replace "edit" and "Delete" text. ?

Please advice.

kind r

Bjørn.
Bjørn-Tore
Top achievements
Rank 1
 answered on 25 Apr 2011
1 answer
135 views
When i click the add new button .
add new button in RadToolBarButton
it's not working ,
look my code tell the suggestion




<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Location.aspx.cs" Inherits="TBS_HelpDesk.Views.Assets.Location"
    MasterPageFile="~/Views/Shared/MasterPage.Master" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
    <telerik:RadCodeBlock runat="server" ID="radCodeBlock">
        <script type="text/javascript">
            function onToolBarClientButtonClicking(sender, args) {
                var grid = $find("<%=RadGrid1.ClientID %>");
                debugger;
                var comandName = args.get_item().get_commandName();
                if (comandName == "Filter") {
                    if (grid.get_masterTableView().get_isFilterItemVisible()) {
                        grid.get_masterTableView().hideFilterItem();
                    }
                    else {
                        grid.get_masterTableView().showFilterItem();
                    }
                }
            }
            function getOuterHTML(obj) {
                if (typeof (obj.outerHTML) == "undefined") {
                    var divWrapper = document.createElement("div");
                    var copyOb = obj.cloneNode(true);
                    divWrapper.appendChild(copyOb);
                    return divWrapper.innerHTML
                }
                else
                    return obj.outerHTML;
            }
            function PrintRadGrid() {
                var previewWnd = window.open('about:blank', '', '', false);
                var sh = '<%= ClientScript.GetWebResourceUrl(RadGrid1.GetType(),String.Format("Telerik.Web.UI.Skins.{0}.Grid.{0}.css",RadGrid1.Skin)) %>';
                var shBase = '<%= ClientScript.GetWebResourceUrl(RadGrid1.GetType(),"Telerik.Web.UI.Skins.Grid.css") %>';
                var styleStr = "<html><head><link href = '" + sh + "' rel='stylesheet' type='text/css'></link>";
                styleStr += "<link href = '" + shBase + "' rel='stylesheet' type='text/css'></link></head>";
                var htmlcontent = styleStr + "<body>" + getOuterHTML($find('<%= RadGrid1.ClientID %>').get_element()) + "</body></html>";
                previewWnd.document.open();
                previewWnd.document.write(htmlcontent);
                previewWnd.document.close();
                previewWnd.print();
                previewWnd.close(); // working

            }
        </script>
    </telerik:RadCodeBlock>
    <div style="width: 760px; height: 600px;">
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" UpdatePanelHeight="" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadGrid ID="RadGrid1" runat="server" Skin="Office2007" AllowAutomaticInserts="True"
            AllowAutomaticUpdates="True" GridLines="None" AutoCompleteType="Disabled" AllowFilteringByColumn="True"
            AllowPaging="True" AllowSorting="True" OnRowDataBound="RadGrid1_RowDataBound1"
            OnItemCommand="RadGrid1_ItemCommand">
            <ExportSettings>
                <Pdf PageHeight="297mm" PageWidth="210mm" />
            </ExportSettings>
            <MasterTableView ShowHeadersWhenNoRecords="true" AutoGenerateColumns="False" CommandItemDisplay="Top"
                EditMode="PopUp" EditFormSettings-PopUpSettings-Modal="true">
                <CommandItemTemplate>
                    <telerik:RadToolBar ID="RadToolBar1" runat="server" OnClientButtonClicking="onToolBarClientButtonClicking">
                        <Items>
                            <telerik:RadToolBarButton Text="Cancel editing" CommandName="CancelAll" ImageUrl="images/Cancel.gif"
                                Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'>
                            </telerik:RadToolBarButton>
                            <telerik:RadToolBarButton Text="Add new" CommandName="InitInsert" ImageUrl="../../images/AddRecord.gif"
                                Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'>
                            </telerik:RadToolBarButton>
                            <telerik:RadToolBarButton Text="Filter" CommandName="Filter" ImageUrl="../../images/Filter 3.gif">
                            </telerik:RadToolBarButton>
                            <telerik:RadToolBarButton Text="Print" CommandName="Print" onclick="PrintRadGrid()">
                            </telerik:RadToolBarButton>
                            <telerik:RadToolBarButton Text="Refresh" CommandName="RebindGrid" ImageUrl="../../images/Refresh.gif">
                            </telerik:RadToolBarButton>
                        </Items>
                    </telerik:RadToolBar>
                </CommandItemTemplate>
                <PagerStyle BackColor="#D8EBFC" Mode="NextPrevNumericAndAdvanced" />
                <HeaderStyle CssClass="dataheadcolor" />
                <RowIndicatorColumn>
                    <HeaderStyle Width="20px"></HeaderStyle>
                </RowIndicatorColumn>
                <ExpandCollapseColumn>
                    <HeaderStyle Width="20px"></HeaderStyle>
                </ExpandCollapseColumn>
                <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-Width="10px">
                        <HeaderStyle Width="10px"></HeaderStyle>
                    </telerik:GridEditCommandColumn>
                    <telerik:GridNumericColumn DataField="AddressID" HeaderText="Address ID" SortExpression="AddressID"
                        UniqueName="AddressID" FilterControlWidth="20px" HeaderStyle-Width="120px" ReadOnly="true">
                    </telerik:GridNumericColumn>
                    <telerik:GridBoundColumn DataField="Address_Location_Name" HeaderText="Address Name"
                        SortExpression="Address_Location_Name" UniqueName="Address_Location_Name" FilterControlWidth="40px"
                        HeaderStyle-Width="130px">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address_Line1" HeaderText="Line1" SortExpression="Address_Line1"
                        UniqueName="Address_Line1" FilterControlWidth="40px" HeaderStyle-Width="80px">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address_Line2" HeaderText="Line2" SortExpression="Address_Line2"
                        UniqueName="Address_Line2" FilterControlWidth="40px" HeaderStyle-Width="80px">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address_City" HeaderText="City " SortExpression="Address_City"
                        UniqueName="Address_City" FilterControlWidth="40px" HeaderStyle-Width="90px">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address_State" HeaderText="State" SortExpression="Address_State"
                        UniqueName="Address_State" FilterControlWidth="40px" HeaderStyle-Width="90px">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address_Country" HeaderText="Country" SortExpression="Address_Country"
                        UniqueName="Address_Country" FilterControlWidth="40px" HeaderStyle-Width="90px">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="Address_Postal_Code" HeaderText="Postal Code"
                        SortExpression="Address_Postal_Code" UniqueName="Address_Postal_Code" FilterControlWidth="40px"
                        HeaderStyle-Width="90px">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn CommandName="Delete" ButtonType="ImageButton" HeaderStyle-Width="10px">
                        <HeaderStyle Width="10px"></HeaderStyle>
                    </telerik:GridButtonColumn>
                </Columns>
                <EditFormSettings ColumnNumber="3" CaptionFormatString="Create">
                    <EditColumn UniqueName="EditCommandColumn1">
                    </EditColumn>
                    <FormTemplate>
                        <table cellspacing="2" cellpadding="1" width="100%" border="0">
                            <tr>
                                <td>
                                    <asp:Label runat="server" Text="AddressID" ID="label1"></asp:Label>
                                </td>
                                <td>
                                    <asp:TextBox Width="200px" ID="AddressID" AutoCompleteType="Disabled" runat="server"
                                        Text='<%# Bind("AddressID") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Location Name
                                </td>
                                <td>
                                    <asp:TextBox Width="200px" ID="Address_Location_Name" AutoCompleteType="Disabled"
                                        runat="server" Text='<%# Bind("Address_Location_Name") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Line1
                                </td>
                                <td>
                                    <asp:TextBox Width="200px" ID="Address_Line1" AutoCompleteType="Disabled" runat="server"
                                        Text='<%# Bind("Address_Line1") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Line2
                                </td>
                                <td>
                                    <asp:TextBox Width="200px" ID="Address_Line2" AutoCompleteType="Disabled" runat="server"
                                        Text='<%# Bind("Address_Line2") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    City
                                </td>
                                <td>
                                    <asp:TextBox Width="200px" ID="Address_City" AutoCompleteType="Disabled" runat="server"
                                        Text='<%# Bind("Address_City") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    State
                                </td>
                                <td>
                                    <asp:TextBox Width="200px" ID="Address_State" AutoCompleteType="Disabled" runat="server"
                                        Text='<%# Bind("Address_State") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Country
                                </td>
                                <td>
                                    <asp:TextBox Width="200px" ID="Address_Country" AutoCompleteType="Disabled" runat="server"
                                        Text='<%# Bind("Address_Country") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Postal Code
                                </td>
                                <td>
                                    <asp:TextBox Width="200px" ID="Address_Postal_Code" AutoCompleteType="Disabled" runat="server"
                                        Text='<%# Bind("Address_Postal_Code") %>'></asp:TextBox>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:Button ID="Button1" runat="server" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                    </asp:Button>
                                    <asp:Button ID="Button2" runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel">
                                    </asp:Button>
                                </td>
                            </tr>
                        </table>
                    </FormTemplate>
                    <PopUpSettings Modal="True"></PopUpSettings>
                </EditFormSettings>
            </MasterTableView>
            <ClientSettings>
                <Selecting AllowRowSelect="True" EnableDragToSelectRows="True" />
            </ClientSettings>
        </telerik:RadGrid>
    </div>
</asp:Content>




using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using Telerik.Web.UI;

namespace TBS_HelpDesk.Views.Assets
{
    public partial class Location : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable dtTable = new DataTable();
            string conn = ConfigurationManager.ConnectionStrings["TBSHelpDeskLiveDB_ConnectionString"].ToString();
            SqlDataAdapter sqladp = new SqlDataAdapter();
            SqlConnection sqlconn = new SqlConnection(conn);
            sqlconn.Open();
            try
            {
                string selectQuery = "SELECT AddressID, Address_Location_Name, Address_Line1,Address_Line2,Address_City,Address_State,Address_Country,Address_Postal_Code FROM [Addresses] order by AddressID asc";
                sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);
                sqladp.Fill(dtTable);
                RadGrid1.DataSource = dtTable;

            }
            finally
            {
                sqlconn.Close();
            }
        }
        protected void RadGrid1_RowDataBound1(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("id", e.Row.RowIndex.ToString());
                e.Row.Attributes.Add("onclick", "MarkRow(" + e.Row.RowIndex.ToString() + ");");
                //    e.Row.Attributes.Add("onkeydown", "SelectRow('" + GridView1.ClientID + "'," + e.Row.RowIndex.ToString() + ")");
            }

        }

        protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
        {
            DataTable dtTable = new DataTable();
            string conn = ConfigurationManager.ConnectionStrings["TBSHelpDeskLiveDB_ConnectionString"].ToString();
            SqlDataAdapter sqladp = new SqlDataAdapter();
            SqlConnection sqlconn = new SqlConnection(conn);
            SqlCommand sqlcmd = new SqlCommand();

            if (e.CommandName == RadGrid.PerformInsertCommandName)
            {
                GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;

                TextBox Address_Location_Name = (e.Item as GridEditFormInsertItem)["Address_Location_Name"].Controls[0] as TextBox;
                TextBox Address_Line1 = (e.Item as GridEditFormInsertItem)["Address_Line1"].Controls[0] as TextBox;
                TextBox Address_Line2 = (e.Item as GridEditFormInsertItem)["Address_Line2"].Controls[0] as TextBox;
                TextBox Address_City = (e.Item as GridEditFormInsertItem)["Address_City"].Controls[0] as TextBox;
                TextBox Address_State = (e.Item as GridEditFormInsertItem)["Address_State"].Controls[0] as TextBox;
                TextBox Address_Country = (e.Item as GridEditFormInsertItem)["Address_Country"].Controls[0] as TextBox;
                TextBox Address_Postal_Code = (e.Item as GridEditFormInsertItem)["Address_Postal_Code"].Controls[0] as TextBox;



                try
                {
                    sqlconn.Open();
                    string insertQuery = "INSERT INTO [Addresses] ([Address_Location_Name], [Address_Line1],[Address_Line2],[Address_City],[Address_State],[Address_Country],[Address_Postal_Code]) VALUES ('" + Address_Location_Name.Text + "','" + Address_Line1.Text + "','" + Address_Line2.Text + "','" + Address_City.Text + "','" + Address_State.Text + "','" + Address_Country.Text + "','" + Address_Postal_Code.Text + "')";
                    sqlcmd.CommandText = insertQuery;
                    sqlcmd.Connection = sqlconn;
                    sqlcmd.ExecuteNonQuery();
                    string selectQuery = "SELECT AddressID, Address_Location_Name, Address_Line1,Address_Line2,Address_City,Address_State,Address_Country,Address_Postal_Code FROM [Addresses] order by AddressID asc";
                    sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);
                    sqladp.Fill(dtTable);
                    RadGrid1.DataSource = dtTable;
                    sqlconn.Close();
                }
                catch (Exception ex)
                {
                    RadGrid1.Controls.Add(new LiteralControl("Unable to insert Employee. Reason: " + ex.Message));
                }
                RadGrid1.MasterTableView.IsItemInserted = false;
                RadGrid1.DataBind();
                e.Canceled = true;
            }
            else if (e.CommandName == RadGrid.UpdateCommandName)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;

                RadNumericTextBox AddressID = (e.Item as GridEditableItem)["AddressID"].Controls[0] as RadNumericTextBox;
                TextBox Address_Location_Name = (e.Item as GridEditableItem)["Address_Location_Name"].Controls[0] as TextBox;
                TextBox Address_Line1 = (e.Item as GridEditableItem)["Address_Line1"].Controls[0] as TextBox;
                TextBox Address_Line2 = (e.Item as GridEditableItem)["Address_Line2"].Controls[0] as TextBox;
                TextBox Address_City = (e.Item as GridEditableItem)["Address_City"].Controls[0] as TextBox;
                TextBox Address_State = (e.Item as GridEditableItem)["Address_State"].Controls[0] as TextBox;
                TextBox Address_Country = (e.Item as GridEditableItem)["Address_Country"].Controls[0] as TextBox;
                TextBox Address_Postal_Code = (e.Item as GridEditableItem)["Address_Postal_Code"].Controls[0] as TextBox;

                try
                {
                    sqlconn.Open();
                    string updateQuery = "UPDATE [Addresses] SET [Address_Location_Name] = '" + Address_Location_Name.Text + "', [Address_Line1] = '" + Address_Line1.Text + "',[Address_Line2] ='" + Address_Line2.Text + "',[Address_City] = '" + Address_City.Text + "',[Address_State] = '" + Address_State.Text + "',[Address_Country] = '" + Address_Country.Text + "',[Address_Postal_Code] = '" + Address_Postal_Code.Text + "' WHERE [AddressID] = '" + AddressID.Text + "'";
                    sqlcmd.CommandText = updateQuery;
                    sqlcmd.Connection = sqlconn;
                    sqlcmd.ExecuteNonQuery();
                    string selectQuery = "SELECT AddressID, Address_Location_Name, Address_Line1,Address_Line2,Address_City,Address_State,Address_Country,Address_Postal_Code FROM [Addresses] order by AddressID asc";
                    sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);
                    sqladp.Fill(dtTable);
                    RadGrid1.DataSource = dtTable;
                    sqlconn.Close();
                }
                catch (Exception ex)
                {
                    RadGrid1.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));

                }
                RadGrid1.EditIndexes.Clear();
                RadGrid1.DataBind();
                e.Canceled = true;
            }
            else if (e.CommandName == RadGrid.DeleteCommandName)
            {
                GridDataItem item = (GridDataItem)e.Item;
                string AddressID = item["AddressID"].Text;

                try
                {
                    sqlconn.Open();
                    string deleteQuery = "DELETE FROM [Addresses] WHERE [AddressID] ='" + AddressID + "'";
                    sqlcmd.CommandText = deleteQuery;
                    sqlcmd.Connection = sqlconn;
                    sqlcmd.ExecuteNonQuery();
                    string selectQuery = "SELECT AddressID, Address_Location_Name, Address_Line1,Address_Line2,Address_City,Address_State,Address_Country,Address_Postal_Code FROM [Addresses] order by AddressID asc";
                    sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);
                    sqladp.Fill(dtTable);
                    RadGrid1.DataSource = dtTable;
                    sqlconn.Close();
                }
                catch (Exception ex)
                {
                    RadGrid1.Controls.Add(new LiteralControl("Unable to delete Id. Reason: " + ex.Message));
                    e.Canceled = true;
                }

            }
        }
    }
}
mohamed
Top achievements
Rank 1
 answered on 25 Apr 2011
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?