Gridviews InsertCommand

Hello everyone,
I created a gridview binded via mysql, withount using codebehind.
It works fine, I can see the data, delete and even edit rows via Delete and Update command. But the InsertCommand does not work.
So I have a simple question: is this possible to do it this way or I have to work with code behind?
Here is part of my code:
        <Columns>
            <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:ImageButton ID="Deletebutton" runat="server" ToolTip="Delete" CssClass="icon" CommandName="Delete"
ImageUrl="Images/Delete.png"/>
                    <asp:ImageButton ID="ImageButton1" runat="server" ToolTip="Edit" CssClass="icon" CommandName="Edit"
ImageUrl="~/Images/edit.png"/>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:ImageButton ID="imgbtnUpdate" runat="server" ToolTip="Save" CssClass="icon" ImageUrl="~/Images/Save.png"
CommandName="Update" />
                    <asp:ImageButton ID="imgbtnCancel" runat="server" ToolTip="Cancel" CssClass="icon" ImageUrl="~/Images/Cancel.png"
CommandName="Cancel"/>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:ImageButton ID="imgbtnInsert" runat="server" ToolTip="Add" CssClass="icon" ImageUrl="~/Images/Add.png"
CommandName="Insert"/>
                </FooterTemplate>
           </asp:TemplateField>
            <asp:BoundField DataField="TransactionCategoryId"   SortExpression="TransactionCategoryId"  HeaderText="Id"        
Visible="false" />
            <asp:BoundField DataField="TransactionCategory"     SortExpression="TransactionCategory"    HeaderText="Category" />
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource
        ID="SqlDataSource1"
        runat="server"
        ConnectionString="server=localhost;user id=root;password=;database=mydbtest;Convert Zero Datetime=True;Allow Zero Datetime=True"
        ProviderName="<%$ ConnectionStrings:mytestConnectionString.ProviderName %>"
        SelectCommand="SELECT *
                        FROM `sytransactioncategory`
                        ORDER BY `TransactionCategory`"
        DeleteCommand="DELETE FROM `sytransactioncategory` WHERE TransactionCategoryId=@TransactionCategoryId"
        UpdateCommand="UPDATE `sytransactioncategory` SET TransactionCategory=@TransactionCategory WHERE TransactionCategoryId=@TransactionCategoryId"
        InsertCommand="INSERT INTO `sytransactioncategory` (TransactionCategory) VALUES(@TransactionCategory)" >

Below is my last code showing the footer fields that are supposed to insert.In the UpdateCommand, when I replace @TransactionCategory by @azerty and try to update, I logically have an error message.
But when I replace in the InsertCommand @TransactionCategory by @azerty and try to insert, I do not have an error message. It's like the command is not taken into account. I am running crazy...
    <asp:GridView ID="GvTrnCategory1" runat="server"
         AutoGenerateColumns="False"
        AllowSorting="True"
ShowFooter="true"
        EmptyDataText="No data found"
        DataSourceID="SqlDataSource1"
        DataKeyNames="TransactionCategoryId" >
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:ImageButton ID="Deletebutton" runat="server" ToolTip="Delete" CssClass="icon" ImageUrl="Images/Delete.png"
CommandName="Delete"/>
                    <asp:ImageButton ID="ImageButton1" runat="server" ToolTip="Edit" CssClass="icon" ImageUrl="~/Images/edit.png"
CommandName="Edit"/>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:ImageButton ID="imgbtnUpdate" runat="server" ToolTip="Save" CssClass="icon" ImageUrl="~/Images/Save.png"
CommandName="Update" />
                    <asp:ImageButton ID="imgbtnCancel" runat="server" ToolTip="Cancel" CssClass="icon" ImageUrl="~/Images/Cancel.png"
CommandName="Cancel"/>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:ImageButton ID="imgbtnInsert" runat="server" ToolTip="Add" CssClass="icon" ImageUrl="~/Images/Add.png"
CommandName="Insert"/>
                </FooterTemplate>
           </asp:TemplateField>
            <asp:TemplateField HeaderText="Id" SortExpression="TransactionCategoryId">
                <ItemTemplate>
                    <asp:Label ID="lblTransactionCategoryId" runat="server" Text='<%# Bind("TransactionCategoryId") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>           
                    <asp:Label ID="lblEditTransactionCategoryId" runat="server" Text='<%# Bind("TransactionCategoryId") %>'></asp:Label>         
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtAddFlowId" runat="server" Text='<%# Bind("TransactionCategoryId") %>'></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Transaction Category" SortExpression="TransactionCategory"  >
                <ItemTemplate>
                    <asp:Label ID="lblTransactionCategory" runat="server" Text='<%# Bind("TransactionCategory") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>           
                    <asp:TextBox ID="txtEditTransactionCategory" runat="server" Text='<%# Bind("TransactionCategory") %>'></asp:TextBox>         
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtAddTransactionCategory" runat="server" Text='<%# Bind("TransactionCategory") %>'></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource
        ID="SqlDataSource1"
        runat="server"
        ConnectionString="server=localhost;user id=root;password=;database=mydbtest;Convert Zero Datetime=True;Allow Zero Datetime=True"  
        ProviderName="<%$ ConnectionStrings:mytestConnectionString.ProviderName %>"
        SelectCommand="SELECT *
                        FROM `sytransactioncategory`
                        ORDER BY `TransactionCategory`"
        DeleteCommand="DELETE FROM `sytransactioncategory` WHERE TransactionCategoryId=@TransactionCategoryId"
        UpdateCommand="UPDATE `sytransactioncategory` SET TransactionCategory=@TransactionCategory WHERE TransactionCategoryId=@TransactionCategoryId"
InsertCommand="INSERT INTO `sytransactioncategory` (`TransactionCategory`) VALUES(@TransactionCategory)" >
    </asp:SqlDataSource>

Similar Messages

  • Calculating the total of one column within a GridView

    Hello Everyone!
    I have created a Grid with 6 columns. The 6th column contains monetary values. I have set 'ShowFooter' to 'True' and have styled my footer however there is currently no data in the footer. What
    I'm looking to do is calculate the total of the 6th column and put the value within the footer at the bottom of the 6th column - I'm not sure how to go about this so any assistance would be much appreciated.
    Thank you

    Good morning Griffs, 
    Check this out...http://stackoverflow.com/questions/19808855/calculate-the-sum-of-gridview-column-data-and-store-its-value-in-a-variable
    Danny Rosales .NET Developer

  • Using OleDbDataAdapter Update with InsertCommands and getting blocking locks on Oracle table

    The following code snippet shows the use of OleDbDataAdapter with InsertCommands.  This code is producing many inserts on the Oracle table and is now suffering from contention... all on the same table.  How does the OleDbDataAdapter produce
    inserts from a dataset... what characteristics do these inserts inherent in terms of batch behavior... or do they naturally contend for the same resource. 
    oc.Open();
    for (int i = 0; i < xImageId.Count; i++)
    // Create the oracle adapter using a SQL which will not return any actual rows just the structure
    OleDbDataAdapter da =
       new OleDbDataAdapter("SELECT BUSINESS_UNIT, INVOICE, ASSIGNMENT_ID, END_DT, RI_TIMECARD_ID, IMAGE_ID, FILENAME, BARCODE_LABEL_ID, " +
       "DIRECT_INVOICING, EXCLUDE_FLG, DTTM_CREATED, DTTM_MODIFIED, IMAGE_DATA, PROCESS_INSTANCE FROM sysadm.PS_RI_INV_PDF_MERG WHERE 1 = 2", oc);
    // Create a data set
    DataSet ds = new DataSet("documents");
    da.Fill(ds, "documents");
    // Loop through invoices and write to oracle
    string[] sInvoices = invoiceNumber.Split(',');
    foreach (string sInvoice in sInvoices)
        // Create a data set row
        DataRow dr = ds.Tables["documents"].NewRow();
        ... map the data
        // Populate the dataset
        ds.Tables["documents"].Rows.Add(dr);
    // Create the insert command
    string insertCommandText =
        "INSERT /*+ append */ INTO PS_table " +
        "(SEQ_NBR, BUSINESS_UNIT, INVOICE, ASSIGNMENT_ID, END_DT, RI_TIMECARD_ID, IMAGE_ID, FILENAME, BARCODE_LABEL_ID, DIRECT_INVOICING, " +
        "EXCLUDE_FLG, DTTM_CREATED, DTTM_MODIFIED, IMAGE_DATA, PROCESS_INSTANCE) " +
        "VALUES (INV.nextval, :BUSINESS_UNIT, :INVOICE, :ASSIGNMENT_ID, :END_DT, :RI_TIMECARD_ID, :IMAGE_ID, :FILENAME,  " +
        ":BARCODE_LABEL_ID, :DIRECT_INVOICING, :EXCLUDE_FLG, :DTTM_CREATED, :DTTM_MODIFIED, :IMAGE_DATA, :PROCESS_INSTANCE)";
    // Add the insert command to the data adapter
    da.InsertCommand = new OleDbCommand(insertCommandText);
    da.InsertCommand.Connection = oc;
    // Add the params to the insert
    da.InsertCommand.Parameters.Add(":BUSINESS_UNIT", OleDbType.VarChar, 5, "BUSINESS_UNIT");
    da.InsertCommand.Parameters.Add(":INVOICE", OleDbType.VarChar, 22, "INVOICE");
    da.InsertCommand.Parameters.Add(":ASSIGNMENT_ID", OleDbType.VarChar, 15, "ASSIGNMENT_ID");
    da.InsertCommand.Parameters.Add(":END_DT", OleDbType.Date, 0, "END_DT");
    da.InsertCommand.Parameters.Add(":RI_TIMECARD_ID", OleDbType.VarChar, 10, "RI_TIMECARD_ID");
    da.InsertCommand.Parameters.Add(":IMAGE_ID", OleDbType.VarChar, 8, "IMAGE_ID");
    da.InsertCommand.Parameters.Add(":FILENAME", OleDbType.VarChar, 80, "FILENAME");
    da.InsertCommand.Parameters.Add(":BARCODE_LABEL_ID", OleDbType.VarChar, 18, "BARCODE_LABEL_ID");
    da.InsertCommand.Parameters.Add(":DIRECT_INVOICING", OleDbType.VarChar, 1, "DIRECT_INVOICING");
    da.InsertCommand.Parameters.Add(":EXCLUDE_FLG", OleDbType.VarChar, 1, "EXCLUDE_FLG");
    da.InsertCommand.Parameters.Add(":DTTM_CREATED", OleDbType.Date, 0, "DTTM_CREATED");
    da.InsertCommand.Parameters.Add(":DTTM_MODIFIED", OleDbType.Date, 0, "DTTM_MODIFIED");
    da.InsertCommand.Parameters.Add(":IMAGE_DATA", OleDbType.Binary, System.Convert.ToInt32(filedata.Length), "IMAGE_DATA");
    da.InsertCommand.Parameters.Add(":PROCESS_INSTANCE", OleDbType.VarChar, 10, "PROCESS_INSTANCE");
    // Update the table
    da.Update(ds, "documents");

    Here is what Oracle is showing as blocking locks and the SQL that has been identified with each of the SIDS.  Not sure why there is contention.  There are no triggers or joined tables in this piece of code.
    Here is the SQL all of the SIDs below are running:
    INSERT INTO sysadm.PS_RI_INV_PDF_MERG (SEQ_NBR, BUSINESS_UNIT, INVOICE, ASSIGNMENT_ID, END_DT, RI_TIMECARD_ID, IMAGE_ID, FILENAME, BARCODE_LABEL_ID, DIRECT_INVOICING, EXCLUDE_FLG, DTTM_CREATED, DTTM_MODIFIED, IMAGE_DATA, PROCESS_INSTANCE) VALUES (SYSADM.INV_PDF_MERG.nextval,
    :BUSINESS_UNIT, :INVOICE, :ASSIGNMENT_ID, :END_DT, :RI_TIMECARD_ID, :IMAGE_ID, :FILENAME, :BARCODE_LABEL_ID, :DIRECT_INVOICING, :EXCLUDE_FLG, :DTTM_CREATED, :DTTM_MODIFIED, :IMAGE_DATA, :PROCESS_INSTANCE)
    SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 1150 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1
    SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1
    SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 1156 (BTSUSER,biztprdi,BTSNTSvc64.exe) in instance FSLX3
    SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 6 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX2
    SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 1726 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX2
    SID 1452 (BTSUSER,BIZTPRDI,BTSNTSvc64.exe) in instance FSLX1 is blocking SID 2016 (BTSUSER,biztprdi,BTSNTSvc64.exe) in instance FSLX2

  • How can I display a letter grade in my gridview after calculating percentage into a hidden field in Visual Studio?

    For school I am working on an app using C# in visual studio that allows a student to enter their name, the number of points they earned and the points possible. When they click a submit button, the grade percentage is calculated in a hidden field and then
    the percentage and letter grade should spit out into the gridview. THe issue I am having is trying to figure out how to translate within the if statements regarding the percentage amount equalling whatever letter grade, and then spit that letter grade out
    into the gridview. Here is the code I have so far:
            protected void btnSubmit_Click(object sender, EventArgs e)
                SqlStudent.Insert();
                hdnGradePercent.Value = (((int.Parse("txtPointsEarned.Text")) / (int.Parse("txt.PointsPoss.Text")) * 100)).ToString();
                if ((int.Parse(hdnGradePercent.Value) >= 0) & ((int.Parse(hdnGradePercent.Value) <= 59)))
    (this is where I am having trouble. I can't figure out how to get the letter grade and percent to spit out into the   gridview.)
                else if ((int.Parse(hdnGradePercent.Value) >= 60) & ((int.Parse(hdnGradePercent.Value) <= 69)))
                else if ((int.Parse(hdnGradePercent.Value) >= 70) & ((int.Parse(hdnGradePercent.Value) <= 79)))
                else if ((int.Parse(hdnGradePercent.Value) >= 80) & ((int.Parse(hdnGradePercent.Value) <= 89)))
                else if ((int.Parse(hdnGradePercent.Value) >= 90) & ((int.Parse(hdnGradePercent.Value) <= 100)))
    Any help would be greatly appreciated! I've been stuck on this for hours and I"m losing my mind!!

    Please post ASP.NET questions in the ASP.NET forums (http://forums.asp.net ).

  • How to restrict number of rows display using ig:gridView

    Hi
    All
    How to restrict number of rows display using <ig:gridView datasource="{mybean.mylist}">
    i am getting 10 rows using data_row . i wanna show only first 5 rows .
    pageSize ="5" will be ok . but it displays remaining rows in next page. but i want to display only first 5 rows . is there any attribute to restrict number of rows.
    thanks
    rambhapuri

    I have no idea which component you're talking about. If want to discuss here about a non-Sun JSF component, then please mention about the name, version and build in detail. You can also consider posting this question at the website/forum/mailinglist of the component manfacturer rather than here. At least I can tell you that the Sun JSF h:dataTable has the 'rows' attribute for that. I can also suggest you to just take a look in the TLD documentation of the component in question. There should be all possible attributes listed with a detailed explanation about the behaviour.

  • Want to fix four items per row in a gridview in Windows Phone 8.1 app. I am using data binding.

    No of items in a row of grid varies for different resolution WP devices. How can it be fix to say 4 items per row. Here is xaml:
    <DataTemplate x:Key="DataTemplate1">
    <Grid Margin="8,0">
    <Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" Margin="0,9.5,0,0">
    <Image x:Name="image" Height="100" Width="100" Source="{Binding ImageName}" >
    </Image>
    </Border>
    <TextBlock Grid.Row="1" Text="{Binding Name}" />
    </Grid>
    </DataTemplate>
    <Grid>
    <GridView ItemTemplate="{StaticResource DataTemplate1}" ItemsSource="{Binding Data1}" HorizontalAlignment="Center" >
    </GridView>
    </Grid>

    You could change the GridView's size to datatemplate size * 4 (and allow for any padding). This would have the side-effect of making the GridView a different size on different screens though (e.g. on a higher-resolution screen the grid will be smaller, but
    will have the correct number of rows).
    I'm not sure if it's possible, but see if you can adjust the datatemplate's size at runtime to be 1/4 the gridview size. This will scale nicely if it works.
    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

  • Control 'ctl00_SPWebPartManager1_g_d4fb972b_26ec_4065_9c89_80b51b384492_gvwikireport' of type 'GridView' must be placed inside a form tag with runat=server.

    Hi,
    I have written code for 'Export To Excel' in the visual web part as below
    //ascx file    
    <table>
        <tr>
            <td>From Date:</td>
            <td><SharePoint:DateTimeControl ID="dtFromDate" runat="server" DateOnly="True" /></td>
        </tr>
        <tr>
            <td>To Date:</td>
            <td><SharePoint:DateTimeControl ID="dtToDate" runat="server" DateOnly="True" TimeOnly="False" /></td>
        </tr>
        <tr>
          <td>Report Type:<asp:DropDownList ID="ddlreporttype" runat="server"><asp:ListItem>Consolidated</asp:ListItem><asp:ListItem>Question Wise</asp:ListItem></asp:DropDownList></td>
            <td>
                <br />               
                <asp:GridView ID="gvwikireport" runat="server">
                </asp:GridView>                   
            </td>
        </tr>   
        <tr>
            <td><asp:Button ID="btnExportToExcel" runat="server" Text="Export To Excel" OnClick="btnExportToExcel_Click"/></td>
        </tr>  
        </table>
    //cs file
    protected void Page_Load(object sender, EventArgs e)
                if (!Page.IsPostBack)
                    BindGridview();
    private void BindGridview()
                DataTable dt = new DataTable();
                dt.Columns.Add("UserId", typeof(Int32));
                dt.Columns.Add("UserName", typeof(string));
                dt.Columns.Add("Education", typeof(string));
                dt.Columns.Add("Location", typeof(string));            
                dt.Rows.Add(1, "SureshDasari", "B.Tech", "Chennai");
                dt.Rows.Add(2, "MadhavSai", "MBA", "Nagpur");
                dt.Rows.Add(3, "MaheshDasari", "B.Tech", "Nuzividu");
                dt.Rows.Add(4, "Rohini", "MSC", "Chennai");
                dt.Rows.Add(5, "Mahendra", "CA", "Guntur");
                dt.Rows.Add(6, "Honey", "B.Tech", "Nagpur");
                gvwikireport.DataSource = dt;
                gvwikireport.DataBind();
    protected void btnExportToExcel_Click(object sender, EventArgs e)
                Page.Response.ClearContent();
                Page.Response.Buffer = true;
                Page.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "WikiReport.xls"));
                Page.Response.ContentType = "application/ms-excel";
                StringWriter sw = new StringWriter();
                HtmlTextWriter htw = new HtmlTextWriter(sw);
                gvwikireport.AllowPaging = false;
                BindGridview();
                //Change the Header Row back to white color
                gvwikireport.HeaderRow.Style.Add("background-color", "#FFFFFF");
                //Applying stlye to gridview header cells
                for (int i = 0; i < gvwikireport.HeaderRow.Cells.Count; i++)
                    gvwikireport.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
                gvwikireport.RenderControl(htw);
                Page.Response.Write(sw.ToString());
                Page.Response.End();            
    But after clicking the 'Export To Excel' button i am getting the below error
    Control 'ctl00_SPWebPartManager1_g_d4fb972b_26ec_4065_9c89_80b51b384492_gvwikireport' of type 'GridView' must be placed inside a form tag with runat=server.
    In case if i am modifying the code as below I am getting error as 'page can have only one server tag'.
    <form id="frmgrdview" runat="server">
     <asp:GridView ID="gvwikireport" runat="server">
                 </asp:GridView></form>
    So please share your ideas/thoughts on the same.
    Regards,
    Sudheer 
    Thanks & Regards, Sudheer

    Hi,
    According to your post, my understanding is that you fail to export to excel.
    I create a demo as below, it works well.
    <table>
    <tr>
    <td>
    <asp:Label ID="Label1" runat="server" Text="Name"></asp:Label>
    </td>
    <td>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>
    <asp:GridView ID="gvwikireport" runat="server">
    </asp:GridView>
    </td>
    <td>
    <br />
    <asp:Button ID="btnExportToExcel" runat="server"
    onclick="btnExportToExcel_Click" Text="Export to excel" />
    </td>
    </tr>
    </table>
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Data;
    using System.IO;
    namespace Export_to_Excel.VisualWebPart1
    public partial class VisualWebPart1UserControl : UserControl
    protected void Page_Load(object sender, EventArgs e)
    if (!Page.IsPostBack)
    BindGridview();
    private void BindGridview()
    DataTable dt = new DataTable();
    dt.Columns.Add("UserId", typeof(Int32));
    dt.Columns.Add("UserName", typeof(string));
    dt.Columns.Add("Education", typeof(string));
    dt.Columns.Add("Location", typeof(string));
    dt.Rows.Add(1, "SureshDasari", "B.Tech", "Chennai");
    dt.Rows.Add(2, "MadhavSai", "MBA", "Nagpur");
    dt.Rows.Add(3, "MaheshDasari", "B.Tech", "Nuzividu");
    dt.Rows.Add(4, "Rohini", "MSC", "Chennai");
    dt.Rows.Add(5, "Mahendra", "CA", "Guntur");
    dt.Rows.Add(6, "Honey", "B.Tech", "Nagpur");
    gvwikireport.DataSource = dt;
    gvwikireport.DataBind();
    protected void btnExportToExcel_Click(object sender, EventArgs e)
    Page.Response.ClearContent();
    Page.Response.Buffer = true;
    Page.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "WikiReport.xls"));
    Page.Response.ContentType = "application/Excel";
    StringWriter sw = new StringWriter();
    HtmlTextWriter htw = new HtmlTextWriter(sw);
    gvwikireport.AllowPaging = false;
    BindGridview();
    //Change the Header Row back to white color
    gvwikireport.HeaderRow.Style.Add("background-color", "#FFFFFF");
    //Applying stlye to gridview header cells
    for (int i = 0; i < gvwikireport.HeaderRow.Cells.Count; i++)
    gvwikireport.HeaderRow.Cells[i].Style.Add("background-color", "#df5015");
    gvwikireport.RenderControl(htw);
    Page.Response.Write(sw.ToString());
    Page.Response.End();
    The result is as below:
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Update a gridview when contact form is closing

    Hallo
    Hope all are well.
    I got a NewCompany form that uses a clickevent to open another form to fill in contact details.
    But this then updates field in sql. I want to update the gridview with the new information when the contactform has been filled in.
    I created a method to run which is populating the main form, I made it public so can access the method on the contactform.
    below the code to update the gridview, this part is working when executing from the NewCompany.
    The next code is when I done the update and want to update the form.
    public void PopulateGridView()
    CreateConnection();
    try
    con = new SqlConnection(constring);
    cmd = new SqlCommand("Select CompanyDetailID, ContactID, Name, Surname, JobTitle, Cellphone, Landline, Extension, Email, Birthday, Notes " +
    "from ContactDetails " +
    "where CompanyDetailID = @SelectedSubDivID ",con);
    cmd.Parameters.AddWithValue("@SelectedCompanyID", SelectCompanyID);
    cmd.Parameters.AddWithValue("@SelectedSubDivID", SelectSubdivisionID);
    sda = new SqlDataAdapter(cmd);
    dt = new DataTable();
    sda.Fill(dt);
    dgContactInfo.DataSource = dt;
    dgContactInfo.Columns[0].Visible = false;
    dgContactInfo.Columns[1].Visible = false;
    catch (Exception ex)
    MessageBox.Show(ex.ToString());
    finally
    The code from the subform trying to execute the top part.
    private void txtSave_Click(object sender, EventArgs e)
    if (CheckEntryValidation())
    MessageBox.Show("All Filled In");
    if (ContactID == 0)
    try
    CreateConnection();
    con = new SqlConnection(constring);
    con.Open();
    cmd = new SqlCommand("INSERT INTO ContactDetails (CompanyDetailID, Name, Surname, JobTitle, Cellphone, Landline, Extension, " +
    "Email, Birthday, Notes) " +
    "VALUES (@CompanyDetailIDs, @Names, @Surnames, @JobTitles, @Cellphones, @Landlines, @Extensions, " +
    "@Emails, @Birthdays, @Notess) ", con);
    cmd.Parameters.AddWithValue("@CompanyDetailIDs", DetailID);
    cmd.Parameters.AddWithValue("@Names", this.txtName.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Surnames", this.txtSurname.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@JobTitles", this.txtJobTitle.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Cellphones", this.txtCellphone.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Landlines", this.txtLandline.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Extensions", this.txtExtension.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Emails", this.txtEmail.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Birthdays", dateOnly);
    cmd.Parameters.AddWithValue("@Notess", this.txtNotes.Text.ToString().Trim());
    cmd.ExecuteNonQuery();
    MessageBox.Show("Succesfully added");
    NewCompany Updgridview = new NewCompany();
    Updgridview.PopulateGridView();
    this.Close();
    catch (Exception ex)
    MessageBox.Show(ex.ToString());
    finally
    con.Close();
    labjac

    Hallo Fouad
    Thanks for the reply, below the code extractions I tried. it complains about a Null reference not set as a object, (Please see pictures attached). I think I might be doing something wrong. please let me know what parts you need to assist.
    Calling the ContactDetailsPopup form form the NewCompany form that got the gridview for updating:
    private void txtAddContact_Click(object sender, EventArgs e)
    if (SelectSubdivisionID != 0)
    GridSelectDetailsID = SelectSubdivisionID;
    GridSelectContactID = 0;
    ContactDetailsPopup ContactPage = new ContactDetailsPopup(GridSelectContactID, GridSelectDetailsID);
    ContactPage.Show();
    else
    MessageBox.Show("Please select Company and Sub Division first");
    The Constructor (I think)..
    private NewCompany UpdateMainView;
    public ContactDetailsPopup(NewCompany Ncomp)
    InitializeComponent();
    UpdateMainView = Ncomp;
    The Update and save:
    private void txtSave_Click(object sender, EventArgs e)
    if (CheckEntryValidation())
    if (ContactID == 0)
    try
    CreateConnection();
    con = new SqlConnection(constring);
    con.Open();
    cmd = new SqlCommand("INSERT INTO ContactDetails (CompanyDetailID, Name, Surname, JobTitle, Cellphone, Landline, Extension, " +
    "Email, Birthday, Notes) " +
    "VALUES (@CompanyDetailIDs, @Names, @Surnames, @JobTitles, @Cellphones, @Landlines, @Extensions, " +
    "@Emails, @Birthdays, @Notess) ", con);
    cmd.Parameters.AddWithValue("@CompanyDetailIDs", DetailID);
    cmd.Parameters.AddWithValue("@Names", this.txtName.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Surnames", this.txtSurname.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@JobTitles", this.txtJobTitle.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Cellphones", this.txtCellphone.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Landlines", this.txtLandline.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Extensions", this.txtExtension.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Emails", this.txtEmail.Text.ToString().Trim());
    cmd.Parameters.AddWithValue("@Birthdays", dateOnly);
    cmd.Parameters.AddWithValue("@Notess", this.txtNotes.Text.ToString().Trim());
    cmd.ExecuteNonQuery();
    MessageBox.Show("Succesfully added");
    UpdateMainView.PopulateGridViewWithParm(DetailID, ContactID);
    this.Close();
    catch (Exception ex)
    MessageBox.Show(ex.ToString());
    finally
    con.Close();
    The Update Gridview Method on the NewCompany Main page where the gridview is present.
    public void PopulateGridViewWithParm(int CompanyID, int SubDivID)
    int loc_SelectCompanyID = CompanyID;
    int loc_SelectSubDivisionID = SubDivID;
    CreateConnection();
    try
    con = new SqlConnection(constring);
    cmd = new SqlCommand("Select CompanyDetailID, ContactID, Name, Surname, JobTitle, Cellphone, Landline, Extension, Email, Birthday, Notes " +
    "from ContactDetails " +
    "where CompanyDetailID = @SelectedSubDivID ", con);
    cmd.Parameters.AddWithValue("@SelectedCompanyID", CompanyID);
    cmd.Parameters.AddWithValue("@SelectedSubDivID", SubDivID);
    sda = new SqlDataAdapter(cmd);
    dt = new DataTable();
    sda.Fill(dt);
    dgContactInfo.DataSource = dt;
    dgContactInfo.Columns[0].Visible = false;
    dgContactInfo.Columns[1].Visible = false;
    catch (Exception ex)
    MessageBox.Show(ex.ToString());
    finally
    Please note that the updateGridview is working correctly when updated from the NewCompany page where the Gridview is present. 
    Regards,
    Jacques.
    labjac

  • Webpart button to generate pdf and print Gridview

    Hi
    Does anyone know how to generate a PDF that displays the contents of a Gridview using a button on a webpart?
    I'm using Sharepoint 2010 with iTextSharp but am getting javascript error 'RegisterForEventValidation can only be called during Render()'.
    Thanks in advance.

    Hi,
    According to your post, my understanding is that you wanted to convert the webpart content to pdf.
    To solve this problem, you can set EventValidation to false for the page and also override VerifyRenderingInServerForm in code behind to check whether it works.
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="PDFFormExample.VisualWebPart1.VisualWebPart1UserControl" EnableEventValidation="false"%>
    public override void VerifyRenderingInServerForm(Control control)
    /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
    server control at run time. */
    http://www.aspdotnet-suresh.com/2011/04/registerforeventvalidation-can-only-be.html
    http://www.codeproject.com/Questions/45450/RegisterForEventValidation-can-only-be-called-duri
    John Chapman had written a blog about using iTextSharp with SharePoint 2010, you can also check the steps with it, then check whether it works.
    http://www.sharepointjohn.com/sharepoint-2010-fill-out-and-flatten-pdf-forms-with-itextsharp/
    Thanks & Regards,
    Jason
    Jason Guo
    TechNet Community Support

  • Theme icon images in GridView

    Not sure if this is something that I've read about already somewhere, but I've been spinning my wheels a bit trying to come up with a better solution.
    In most of my GridViews, I have already modified them a fair amount (added extra data by looping through the gridview rows in the OnPreRender) so while I was there, I assigned the column image URLs inside the code there using the NPBasePage.ThemesPath call. 
    I've come to the Saved Lists page and I'd be okay with just modifying it to have my theme path's add/remove images, but seems there must be a better way than looping through the gridview and changing it there.  Now that I think about it though, it seems to be doing some processing regardless of what you assign to the ImageUrl in the item template which is probably why I had ended up doing it inside that loop to begin with. 
    Is there a better way of doing this?
    Thanks.

    I'm not sure if I fully understand what you're trying to do .. but instead of your code looping over the gridview I normally add my control in the ItemTemplate itself and it will get called for each row in the grid. The event you decide to run your code in is still up to you.
    Have you tried just naming the icons with the same name in your theme folder? WebTools supports a dynamic image lookup so for example if there is an image "add.gif" that is currently in the assets/common/buttons folder, if you create your own image called add.gif and place it in your theme folder, WebTools should use this one automatically. This works in some places .. but I'm not sure if it is missing from some pages.

  • In edit mode in gridview everytime ihave to select dropdownlist otherwise its store first value

    <asp:GridViewID="GVTrouserJobWork"runat="server"  
    AutoGenerateColumns="False"CssClass="Gridview"HeaderStyle-BackColor="#4B6D9D
    "DataKeyNames="TrouserJobID"
    OnRowCancelingEdit="GVTrouserJobWork_RowCancelingEdit"OnRowDeleting="GVTrouserJobWork_RowDeleting"
    OnRowEditing="GVTrouserJobWork_RowEditing"OnRowUpdating="GVTrouserJobWork_RowUpdating">
    <Columns>
    <asp:TemplateFieldHeaderText="StyleNo"
    <asp:LabelID="lblStyleNo"runat="server"Text='<%#Eval("StyleNo")
    %>'/>
    <asp:DropDownList Width="60px"  DataSource='<%# GetStyleNo() %>' DataTextField="StyleNo"
                                        DataValueField="StyleNo" ID="StyleNo"
    runat="server">
                                    </asp:DropDownList>
    </EditItemTemplate>
    <ItemTemplate>
    <asp:LabelID="lblStyleNo1"runat="server"Text='<%#Eval("StyleNo")
    %>'/>
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>
    public
    DataSetGetStyleNo() {
    SqlConnectionmyConnection =
    newSqlConnection(ConfigurationManager.ConnectionStrings["constring"].ToString());
    SqlCommandcmd =
    newSqlCommand();
                    cmd.Connection = con;
                    cmd.CommandText =
    "StleMasterList";
                    cmd.CommandType =
    CommandType.StoredProcedure;
    SqlDataAdapterad =
    newSqlDataAdapter("StleMasterList",
    myConnection);
    //SelectDDCompanyName
    DataSetds =
    newDataSet();
                    ad.Fill(ds,
    "StleMasterList");
    return
    ds;
    StleMasterList = Select StyleNo from Stylemaster
    protectedvoid
    GVTrouserJobWork_RowUpdating(objectsender,
    GridViewUpdateEventArgse)
    intTrouserOrderID =
    Convert.ToInt32(GVTrouserOrderDetail.DataKeys[e.RowIndex].Value.ToString());
    DropDownListStyleNo = (DropDownList)GVTrouserOrderDetail.Rows[e.RowIndex].FindControl("StyleNo");
    SqlCommandcmd =
    newSqlCommand("update
    TrouserOrders set StyleNo='"+
    StyleNo.SelectedValue.ToString() + "'where
    TrouserOrderID="+ TrouserOrderID, con);
     cmd.ExecuteNonQuery();
     con.Close();
    lblresult.ForeColor =Color.Green;
    lblresult.Text = " Details Updated successfully";
    GVTrouserOrderDetail.EditIndex = -1;
    BindTrouserOrderDetails();
    Actually I get dropdown in editmode but when without selecting dropdownlist if I update it it select first value of dropdown list.
    if have two dropdownlist in gridview and I want to update only one I cant do this every time I have to select both
    dropdownlist .

    Hello Fresherss,
    I think the ASP.NET forum will be more suitable for this thread:
    http://forums.asp.net/
    There are ASP.NET experts who will help you better.
    Regards.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Count word appearance and show in gridview

    Hello all, I am working on a project with multi tables. In one table the user selects one of 13 categories that they are uploading images to. Each category has a sub category. On the main page , I have a grid view for each category that list the subcategories.
    Much the way a classified ads would work, I want to be able to show the number of each image in the subcategories as in below.
    Name
    number
      of images
    Subcategory
    3
    Subcategory
    2
    Subcategory
    4
    Subcategory
    23
    Subcategory
    1
    Subcategory
    3
    Subcategory
    332
    Subcategory
    1
    Subcategory
    3
    Subcategory
    2
    Subcategory
    3
    I am using the count function in stored procedure that counts the number of images in subcategory entered
    select subcategory, count(*) as mycount from userinput group as subcategory.
    which gives me the count of each item under the subcategory listed by the user.
    I need to be able to take this count and show it next the  item name in the 13 tables that list the subcategories.
    So I am counting the entries from one table (datasource) and showing the number of entries in 13 different tables (GridViews) based on the name of the subcategory.
    this has to be done when the page loads so the usre will see the correct amount of images in the 13  grid views.
    Any ideas on how to do this??
    Thanks in advance.

    Hi Jasonpauthement,
    If I understand correctly, you want to display the categories and corresponding subcategories in the main table, then display the each subcategory and the corresponding count images in another 13 tables. If in this scenario, we can refer to the steps below
    to display another 13 tables:
    Drag a table with subcategory and the corresponding count images values to the design surface.
    Then use a list with the same dataset to contain the table.
    In Row Groups, Right-click the Details group to add a group grouped on subcategory.
    Then each subcategory and its corresponding count images values would be displayed in the list. If there are any misunderstanding, please elaborate the issue for further investigation.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Out-GridView Question

    Hello,
    I'm wondering if you can control the window size when using Out-GridView? For example:
    Get-Service | Out-GridView
    When this is run the window is showing more space than what I need; is it possible to have it shrink the window size to fit the results?

    I am not aware of any option, or parameter, to control the size of the form created by Out-GridView. It also doesn't seem change size depending on the content that is being displayed. You may need to create your own GUI element if you want to determine
    the size.

  • Issue with scroll viewer using itemswrapgrid in gridview?

    Hi,
    am developing a windows phone 8.1 app using C# and xaml.
    i need to wrap my gridviewitems vertically.
    I have 10 GridView items in my GridView am using the below code to wrap my gridview items,
    but am able to see only 6 items, the scrollviewer is not coming vertically even though there are some more items.
    (In the below code for reference i just added only one grid view item but i have 10 gridview items in my code ,
    for every gridview item the height and width are 175 and 175 respectively)
    <Page.Resources>
            <ItemsPanelTemplate x:Key="GridViewItemsPanel">
                <ItemsWrapGrid Orientation="Vertical" />
            </ItemsPanelTemplate>
        </Page.Resources>
     <GridView x:Name="landscapeGridview"  
                    HorizontalContentAlignment="Stretch"
                      HorizontalAlignment="Stretch"
                      VerticalAlignment="Stretch"
                      ItemClick="GridView_ItemClick"
                      IsItemClickEnabled="True" 
                      ItemsPanel="{StaticResource GridViewItemsPanel}"
                     ScrollViewer.HorizontalScrollMode="Disabled"
                     ScrollViewer.VerticalScrollMode="Enabled"
                     ScrollViewer.HorizontalScrollBarVisibility="Visible"
                     ScrollViewer.VerticalScrollBarVisibility="Auto"
                      Grid.Row="2" Padding="10,0,0,0">   
    <GridViewItem Height="175" Width="175" Margin="0,5,5,0">
                            <Border Height="165" Width="165"
                        Tag="Notes" Background="#DDECEF">
                                <Grid>
                                    <Image Source="Assets/.png" Margin="0,0,0,0"></Image>
                                    <Image Source="Assets/.png" Margin="0,20,20,0" HorizontalAlignment="Right"
                                       VerticalAlignment="Top" Height="40" Visibility="Collapsed"></Image>
                                    <StackPanel    Background="{StaticResource ListViewItemOverlayBackgroundThemeBrush}"  
                                                     VerticalAlignment="Bottom" Margin="0,0,0,0" Height="30"
    Orientation="Horizontal"
                                               >
                                        <TextBlock Text="" FontSize="20"
                                 Margin="50,0,0,0"
                                   HorizontalAlignment="Center" 
                                            RequestedTheme="Dark"
                                   ></TextBlock>
                                        <TextBlock x:Name="notescounttxtblk" VerticalAlignment="Center" Margin="30,0,0,10"
                                          FontSize="20"></TextBlock>
                                    </StackPanel>
                                </Grid>
                            </Border>
                        </GridViewItem>
    </GridView>
    How to get the scroll viewer to view all the items vertically?
    Any help please?

    Hi Santhosh,
    Per my understanding, this issue is related to container definition where you put your GridView control. In this case, it is the Grid container.
    First you can see a working sample,
    https://code.msdn.microsoft.com/windowsapps/ListViewSimple-d5fc27dd. See the scenario 1 in windows phone project, I can reproduce your issue by setting the height of RowDefinition to “auto” where the GridView control sitting in. You need to check the height
    and width property of the layout. See more information about layout in XAML.
    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh465337.aspx.
    You’ve not mentioned the definition of the Grid layout, I assume you need change the RowDefinition. If you don’t know how, please see details in above code sample.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • [Sorting Problem In The GridView]

    I'm using the oracle 10.2.02 beta client with the VisualStudio.NET 2005.
    The problem is that the sorting function in the GridView doesn't work.
    Is there any way to "connect" the SqlDataSource tool with the oracle connection through a DataSet ? That is to say, the only way to enable sorting in the GridView is to connect it with the SqlDataSource object (accordind to the MSDN help). The SqlDataSourceMode enable us to use a DataSet into the SqlDataSourse but I can't fint HOW....
    Any suggestions?

    Thanks Peluka.
    But even I don't enhance the vendor search help, I still found that the original standard version has this problem after sorting.
    Is that the program bug?
    Have anyone encountered this problem before?

Maybe you are looking for

  • How many computers can you sync the ipad2 to?

    How many computers can I sync the Ipad2 to? My Grandson is coming form out of town nad I wanted to have everything setup when he arrives. He will then take the Ipad2 with him home. Will he have problems at home when will sync to his home computer?

  • Imac no longer recognizes external hard drive

    my iMac no longer recognizes my external hard drive. An icon used to be on my desktop, at times it would disappear and come back, but it has remained elusive for the past couple of months and is NOWHERE to be found. It doesn't even show up in the Dis

  • CC will not allow After Effects CS6 to Update

    I am a frequent After Effects CS6 user; not so long ago I started a subsciption with Adobe Creative Cloud and I've had nothing but issues with it. The CC desktop would crash my whole system on launch, so I cancelled my subsciption and uninstalled any

  • ASM UPGRADE

    Hi, I have some doubt in ASM Upgrade and thats what I would like to discuss this issue here.If I am going to upgrade database,clusterware and asm then the approach should be like below:--> Database version from 10.1.0.5 to 10.2.0.4 OS AIX 5.3 TL8 (1)

  • Create a floating daughter window in pdf?

    For my company's product catalog, I'm looking to make a floating window with the catalog's index on it that stays with you as you scroll down. Imagine a two page spread where the page on the right is much smaller and holds its position on your screen