Click here to Skip to main content
16,020,990 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Good Afternoon ,


My .aspx file is given below.

XML
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
         <div class="ContentClass">
         <asp:TabContainer ID="AssetTransactionTab" runat="server" ActiveTabIndex="0" CssClass="Tab"   Width="794px" Height="290px">
         <asp:TabPanel ID="NewTransaction"  runat="server"  HeaderText="New Transaction" >
         <ContentTemplate>

XML
<asp:UpdatePanel ID="DetailUpdatePanel"  runat="server">
             <ContentTemplate>
            <table align="center" style="width: 666px">
             <tr>
             <td class="lableColumn"><asp:Label ID="lblAssetID" runat="server" Text="Asset ID:"></asp:Label> </td>
             <td><asp:DropDownList ID="ddlAssetID" runat="server"
                     DataSourceID="ddlAssetIDSource" DataTextField="AssetDescription"
                     DataValueField="AssetID" CssClass="ddlstyle"></asp:DropDownList>
                 <asp:SqlDataSource ID="ddlAssetIDSource" runat="server"
                     ConnectionString="<%$ ConnectionStrings:DeemahAssetConnectionString %>"
                     SelectCommand="GetAssetDropDown" SelectCommandType="StoredProcedure">
                 </asp:SqlDataSource>
                 </td>
                   <td class="lableColumn"><asp:Label ID="lblEmployeeID" runat="server" Text="Employee ID:"></asp:Label> </td>
              <td><asp:DropDownList ID="ddlEmployeeID" runat="server"
                      DataSourceID="ddlEmployeeIDSource" DataTextField="EmployeeName"
                      DataValueField="EmployeeID" CssClass="ddlstyle" Width="200px"></asp:DropDownList>
                  <asp:SqlDataSource ID="ddlEmployeeIDSource" runat="server"
                      ConnectionString="<%$ ConnectionStrings:DeemahAssetConnectionString %>"
                      SelectCommand="GetEmployeeDropDown" SelectCommandType="StoredProcedure">
                  </asp:SqlDataSource>
                 </td>
             </tr>
             <tr>
              <td class="lableColumn"><asp:Label ID="lblSupplierID" runat="server" Text="Supplier ID:"></asp:Label></td>
             <td><asp:DropDownList ID="ddlSupplierID" runat="server"
                     DataSourceID="ddlSupplierIDSource" DataTextField="VendorName"
                     DataValueField="VendorID" CssClass="ddlstyle"></asp:DropDownList>
                 <asp:SqlDataSource ID="ddlSupplierIDSource" runat="server"
                     ConnectionString="<%$ ConnectionStrings:DeemahAssetConnectionString %>"
                     SelectCommand="GetVendorDropDown" SelectCommandType="StoredProcedure">
                 </asp:SqlDataSource>
                 </td>
                 <td class="lableColumn"><asp:Label ID="lblIssuedReceivedDate" runat="server" Text="Issued/Received Date:"></asp:Label></td>
             <td><asp:TextBox ID="txtIssuedReceivedDate" runat="server" CssClass="txtstyle"></asp:TextBox>
              <asp:ImageButton ID="imgIssuedReceivedDate" runat="server" ImageUrl="~/Images/btn_calicon.gif" />
                 <asp:CalendarExtender ID="calIssuedReceivedDate" runat="server" TargetControlID="txtIssuedReceivedDate" PopupButtonID="imgIssuedReceivedDate">
                 </asp:CalendarExtender></td>
             </tr>
              <tr>
               <td class="lableColumn"><asp:Label ID="lblLocationID" runat="server" Text="Location ID:"></asp:Label></td>
             <td><asp:DropDownList ID="ddlLocationID" runat="server"
                     DataSourceID="ddlLocationSource" DataTextField="LocationName"
                     DataValueField="LocationID" CssClass="ddlstyle"></asp:DropDownList>
                 <asp:SqlDataSource ID="ddlLocationSource" runat="server"
                     ConnectionString="<%$ ConnectionStrings:DeemahAssetConnectionString %>"
                     SelectCommand="GetLocationDropDown" SelectCommandType="StoredProcedure">
                 </asp:SqlDataSource>
                 </td>
                 <td><asp:Button ID="btnAdd" runat="server" Text="ADD" CssClass="Btn"
                         onclick="btnAdd_Click"></asp:Button></td>
                 </tr>
             </table>
            </ContentTemplate>
             </asp:UpdatePanel>
             <div>
             <asp:UpdatePanel ID="GridUpdatePanel" runat="server">
             <ContentTemplate>
             <asp:GridView ID="GriDisplay" runat="server" AutoGenerateColumns="False">
             <Columns>
             <asp:TemplateField  HeaderText="Asset">
             </asp:TemplateField>
             <asp:TemplateField  HeaderText="Location">
             </asp:TemplateField>
             </Columns>
             </asp:GridView>
             </ContentTemplate>
             </asp:UpdatePanel>
             </div>
         </div>
         </ContentTemplate>
         </asp:TabPanel>
         </asp:TabContainer>
         </div>
</asp:Content>


and my aspx.cs file is given below.


C#
protected void btnAdd_Click(object sender, EventArgs e)
  {
      ArrayList arr = new ArrayList();
      arr.Add(int.Parse(ddlAssetID.SelectedValue).ToString());
      arr.Add(int.Parse(ddlEmployeeID.SelectedValue).ToString());
      GriDisplay.DataSource = arr;
      GriDisplay.DataBind();
  }


i need when i click "btnAdd" then selected dropdownlist value and textbox value bind with gridview ,means if i select dropdownlist and textbox value and when i click "btnAdd" then one record display in gridview,when i click again "btnAdd" then another record insert in gridview on base of selected value of dropdown and textboxes.

if you have any other ideato do this work then please assist me.

thanks
Posted

1 solution

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dtToGrid = new DataTable();
dtToGrid.Columns.Add("value1", typeof(string));
dtToGrid.Columns.Add("value2", typeof(string));
Session["dtToGrid"] = dtToGrid;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dtToGrid = (DataTable)Session["dtToGrid"];
DataRow drToGrid = dtToGrid.NewRow();
drToGrid["value1"] = ddl1.selectedvalue.Trim();
drToGrid["value2"] = TextBox1.Text.Trim();
dtToGrid.Rows.Add(drToGrid);
GridView1.DataSource = dtToGrid;
GridView1.DataBind();

}
 
Share this answer
 
Comments
mohd vaquas 9-May-11 8:54am    
thanks brother its work now
LakshmiNarayana Nalluri 11-May-11 2:01am    
do n't forget to give vote and mark as answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900