fayenot 0 Newbie Poster
protected void Button2_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ToString());

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];
            CheckBox chkbox = (CheckBox)row.FindControl("chkboxSelect");
            TextBox UnitPrice = (TextBox)row.FindControl("txtUnitPrice");

            if (chkbox.Checked == true)
            {
                try
                {
                    conn.Open();

                    int Supp = Convert.ToInt16(Request.QueryString["SupplierId"]);
                    SqlCommand cmd = new SqlCommand ("INSERT INTO SuppMat (SupplierId, MaterialID, UnitPrice) VALUES (@SupplierId,'" + row.Cells[1].Text + "','" + UnitPrice.Text + "')", conn);
                    cmd.Parameters.AddWithValue("@SupplierId", Supp);
                   
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
                catch
                {
                    Response.Write("");
                }
                finally
                {
                    conn.Close();
                }
            }
           
        }
        
    }

here's my code..my only problem now is that it does not save to the database.. hope you can help me..

fayenot 0 Newbie Poster

on button click event u jusst check what are the checkboxexs clicked.
u can use this function

submit_click
{
for(int i=0;i<=gridview.rows.count-1;i++)
{
checkbox chk=new checkbox();
chk=(checkbox)gridview.rows.findcontrol("chk_name");
if(chk.checked)
{
write the code needed to get unit prices and insert into database
}

}
}

hello thanks for the quick reply...
my problem is how to wirte an SQL statement to insert multiple records.. can you please give me an idea or the code for inserting checked records. i dont konw what code to put in this line
write the code needed to get unit prices and insert into database
}

}

fayenot 0 Newbie Poster

hi....

I have a gridview with rows of info which does not go into edit mode.

A user clicks a checkbox which picks that item and adds a Unit Price

What i need to do is when a user clicks on a button, it should scan through the gridview for all items checked and pick up the Unit Price values and a couple of other field values and insert the information into a sql database

What would be the best way of doing this?

Thanks in advance!

fayenot 0 Newbie Poster

i found some codes on other forums concerning the cancellation of insert in formview if the record already exists. but its giving me an error stating that there is an incorrect sysntax near =?.... can you please tell me what's wrong with this syntax..i will post below the codes.

TextBox Client = (TextBox)FormView1.FindControl("ClientNameTextBox0");
        string ConnectionString = "Data Source=DDDWEB\\SQLEXPRESS;Initial Catalog=Database;Integrated Security=True";
        SqlConnection oConn = new SqlConnection(ConnectionString);
        string strSQL = "Select Count(Client) as TheCount FROM Client WHERE ClientName =? ";
        SqlCommand cmd = new SqlCommand(strSQL, oConn);
        cmd.Parameters.AddWithValue("", Client.Text);
        oConn.Open();
        int Result = (int)cmd.ExecuteScalar();
        if (Result > 0)
        {
            e.Cancel = true;
            Label Duplicate = (Label)FormView1.FindControl("lblDuplicate");
            Duplicate.Text = "There is already an existing record.";
        }
        oConn.Close();

im using sqldata source and if you have any idea on how to cancel insertion if the record already exist please feel free to write your post here..thanks in advance..i badly nedd your help..

fayenot 0 Newbie Poster

hello guys,i managed to search records inside my grdiview.. however after the search,after i've seen my filtered records i want to display again all the records when i erase the words on my search txtbox.. here is my code for my search button.. please help..thanks in advance

protected void Button1_Click(object sender, EventArgs e)
    {

        SqlDataSource1.SelectCommand = "Select * FROM Client WHERE ClientName LIKE '%" + txtSearch.Text + "%' AND Status = @IsStatus AND UserId=@UserId";
        GridView1.DataSourceID = "SqlDataSource1";
        GridView1.DataBind();
    }
fayenot 0 Newbie Poster

hello guys,i managed to search records inside my grdiview.. however after the search,after i've seen my filtered records i want to display again all the records when i erase the words on my search txtbox.. here is my code for my search button.. please help..thanks in advance

protected void Button1_Click(object sender, EventArgs e)
    {

        SqlDataSource1.SelectCommand = "Select * FROM Client WHERE ClientName LIKE '%" + txtSearch.Text + "%' AND Status = @IsStatus AND UserId=@UserId";
        GridView1.DataSourceID = "SqlDataSource1";
        GridView1.DataBind();
    }
fayenot 0 Newbie Poster

Can anyone please help me figure a way on how to search in a gridview using the autocomplete extender. i found some reference in doing such however im having a problem

because in the example he is using objectdatasource while in my example im using sqldatasource.. here is the code that he uses and i cant find a way to convert it to fit my website.. 

 

[System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static string[] GetCompletionList(string prefiText, int count, string contextKey)
    {
        //prefiText: the text the user has entered thus far
        // count: the number of suggestions returned
        //contextKey: the column name to fetch suggestions for
        return new CustomeDataObjetc().GetCompletionList(contextKey, prefiText, count);
    }

The CustomerDataObject is where im having a compilation error when i debug it, i tried replacing it with the name of my sqldatasource however it still did not work.. any other suggestions on searching using autocomplete exter is welcome..thanks..looking forward for your help guys...

fayenot 0 Newbie Poster

I have a table for projects, it has two fields for project_start and project_end both have datetime data type. what should i do so that when the user insert dates on both field it will automatically subtract and place the answer on the duration field... please help.. oh before i forgot, the textbox for the fields are located in a formview...how can i subtract project_start and project_end and put its difference to duration field

fayenot 0 Newbie Poster

do i need to install an IIS to make the sending of email possible??

fayenot 0 Newbie Poster

i already turned off the firewall setting of my PC.. i also enable the internet mail server SMTP in the advanced settings of my firewall... what else should i do? thanks a lot for replying..

fayenot 0 Newbie Poster

sorry typographical error..it should be port 25 instead of 21...:)

fayenot 0 Newbie Poster

hi there.. i need not to construct an email.. asp will automatically send an email concerning their forgotten password. i used the password recovery control. my problem is how to configure my web.config file so that when the user answer the security question, the system will automatically send the password to the user's email-ad... right now i changed the config setting to...

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="myemail@yahoo.com">
        <network host="DDDweb" 
                 port="25"/>
      </smtp>
    </mailSettings>
  </system.net>

i got a different error message...

No connection could be made because the target machine actively refused it 192.168.252.108:21

fayenot 0 Newbie Poster

can anyone help me.. im trying to send an email to a user who forgots his/her password.. i configured my web.config into the codes below but still getting this error message..please help...

<system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="faye@webmaster.com">
        
        <network host="dddweb\sqlexpress"
                 port="25"
                 />
      </smtp>
    </mailSettings>
  </system.net>
fayenot 0 Newbie Poster

database structure

Client Table User Table
ClientId PK| UserId FK| ClientName | Address UserId PK| UserName | Password
int unique indentifier varchar varchar unique identifier varchar varchar
----------------------------------------------------------------------------------------------------
SCENARIO: When a user log in, his client will be displayed and he has the capability to add, edit, or delete records. ( List of clients will be displayed in a gridview, add edit delete will be done by the formview).

PROBLEM: When the user want to insert a new record the UserId field should automatically have the default value of the current logged on user.

please help me!!!!

fayenot 0 Newbie Poster

database structure

Client Table User Table
ClientId PK| UserId FK| ClientName | Address UserId PK| UserName | Password

----------------------------------------------------------------------------------------------------
SCENARIO

fayenot 0 Newbie Poster

hi rajarajan07...
thanks for replying but i already got a solution to the problem.. i only set some of the properties of the gridview to make it work...till next time..:)

fayenot 0 Newbie Poster

hi srikanthkadem....
my problem is already resolved, thanks for trying to help i appreciate it.. i already figured it out through tutorials in the web... till next time..:)

fayenot 0 Newbie Poster

hi there..
thanks for the reply but unfortunately it didnt work for me..i believe there still a code that needs to be added on the selecting event of the datasource(that's only my opinion) but if you guys have some different idea aside from using a sql syntax please feel free to reply in this post...thanks

fayenot 0 Newbie Poster

Scenario: I have 2 gridviews, clientgridview for showing the clients and the projectgridview for showing the projects. If I Click on the Client name on the the clientgridview i will be directed to the project gridview to show the different projects of the client

Problem: when i click on the name of my client, projectgridview displays all the projects that are stored on my database. I need to display only the projects that are associated to the selected client(ProjectId is the PK in m ProjectTable and is FK in ClientTable).

Can anyone help me get the corrent syntax to filter the projectId...
SELECT * FROM Project WHERE ProjectId=@Project;
I used this syntax and it didnt work..hope you guys can figure out how to filter this correctly..

fayenot 0 Newbie Poster
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ClientId"
            CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" 
            GridLines="None">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:DatabaseConnectionString %>" 
            SelectCommand="SELECT * FROM [Client]">
        </asp:SqlDataSource>

here is an example of my code..it is a gridview connected with a datasource..still i does not appear when i debug my application..please i need your help guys..

fayenot 0 Newbie Poster

what could be the possible reason why the gridview and formview doesnt appear when i debug my program.. i connected it to a datasource and have them databound, also already set its visibility property to true...please help..

fayenot 0 Newbie Poster

can anyone tell me what's wrong with my codes below..what does this error mean and how can i get rid of it...looking forward for your help..

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        
      <h3>FormView Example</h3>

        <table cellspacing="10">
            
          <tr>
            <td>
              <asp:GridView ID="ClientGridView" 
                DataSourceID="ClientSqlDataSource" 
                AutoGenerateColumns="false"
                DataKeyNames="ClientID" 
                OnSelectedIndexChanged="ClientGridView_OnSelectedIndexChanged"
                RunAt="Server">
                
                <HeaderStyle backcolor="Navy"
                  forecolor="White" />
                
                <Columns>
                
                  <asp:ButtonField Text="Details..."
                    HeaderText="Show<BR>Details"
                    CommandName="Select"/>  
                
                  <asp:BoundField DataField="ClientName" HeaderText="Client Name"/>
                  <asp:BoundField DataField="Address"   HeaderText="Address"/>                        
                  <asp:BoundField DataField="ContactPerson"  HeaderText="Contact Person"/>
                    
                </Columns>
                
              </asp:GridView>
            
            </td>
                
            <td valign="top">
                
              <asp:FormView ID="ClientFormView"
                DataSourceID="ClientSqlDataSource"
                DataKeyNames="ClientID"     
                Gridlines="Both" 
                OnItemUpdated="ClientFormView_ItemUpdated"
                OnItemDeleted="ClientFormView_ItemDeleted"      
                RunAt="server">
                
                <HeaderStyle backcolor="Navy"
                  forecolor="White"/>
                  
                <RowStyle backcolor="White"/>         
                
                <EditRowStyle backcolor="LightCyan"/>
                                    
                <ItemTemplate>
                  <table>
                    <tr><td align="right"><b>Client ID:</b></td><td><%# Eval("ClientId") %></td></tr>
		    <tr><td align="right"><b>Client Name:</b></td>  <td><%# Eval("ClientName") %></td></tr>
                    <tr><td align="right"><b>Address:</b></td> <td><%# Eval("Address") %></td></tr>
                    <tr><td align="right"><b>Contact Person:</b></td>  <td><%# Eval("ContactPerson") %></td></tr>		
		    <tr><td align="right"><b>Telephone No.:</b></td>  <td><%# Eval("TelNo") %></td></tr>
		    <tr><td align="right"><b>Email:</b></td>  <td><%# Eval("Email") %></td></tr>
                    <tr>
                      <td colspan="2">
                        <asp:LinkButton ID="EditButton"
                                        Text="Edit"
                                        CommandName="Edit"
                                        RunAt="server"/>
                        &nbsp;
                        <asp:LinkButton ID="NewButton"
                                        Text="New"
                                        CommandName="New"
                                        RunAt="server"/>
                        &nbsp;
                        <asp:LinkButton ID="DeleteButton"
                                        Text="Delete"
                                        CommandName="Delete"
                                        RunAt="server"/>
                      </td>
                    </tr>
                  </table>                 
                </ItemTemplate>

                <EditItemTemplate>
                  <table>
                  
                   <tr><td align="right"><b>User:</b></td>
                        <td><asp:TextBox ID="UserTextBox" 
                                         Text='<%# Bind("UserId") %>' 
                                         RunAt="Server" /></td></tr>
                      

                    <tr><td align="right"><b>Project:</b></td>
                        <td><asp:TextBox ID="ProjectTextBox" 
                                         Text='<%# Bind("ProjectId") %>' 
                                         RunAt="Server" /></td></tr>
                    
                    <tr><td align="right"><b>Client Name:</b></td>
                        <td><asp:TextBox ID="EditClientNameTextBox" 
                                         Text='<%# Bind("ClientName") %>' 
                                         RunAt="Server" /></td></tr>

                    <tr><td align="right"><b>Address:</b></td>
                        <td><asp:TextBox ID="EditAddressTextBox" 
                                         Text='<%# Bind("Address") %>' 
                                         RunAt="Server" /></td></tr>
                                         
                                         
                    <tr><td align="right"><b>Contact Person:</b></td>
                        <td><asp:TextBox ID="EditContactPersonTextBox" 
                                         Text='<%# Bind("ContactPerson") %>' 
                                         RunAt="Server" /></td></tr>

                    <tr><td align="right"><b>Telephone Number:</b></td>
                        <td><asp:TextBox ID="EditTelNoTextBox" 
                                         Text='<%# Bind("TelNo") %>' 
                                         RunAt="Server" /></td></tr>
                                         
                    <tr><td align="right"><b>Email:</b></td>
                        <td><asp:TextBox ID="EditEmailTextBox" 
                                         Text='<%# Bind("Email") %>' 
                                         RunAt="Server" /></td></tr>
                    <tr>
                      <td colspan="2">
                        <asp:LinkButton ID="UpdateButton"
                                        Text="Update"
                                        CommandName="Update"
                                        RunAt="server"/>
                        &nbsp;
                        <asp:LinkButton ID="CancelUpdateButton"
                                        Text="Cancel"
                                        CommandName="Cancel"
                                        RunAt="server"/> …
fayenot 0 Newbie Poster

i have the same problem... can anyone help us..please.. deadline is fast approaching and i need an immediate resolution for my problem in my thesis.. i will greatly appreciate a friendly help from you guys..=)