Click here to Skip to main content
16,018,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My design as follows


Leave Type dropdownlist1
From Date textbox1
To Date textbox2
Reason textbox3

Submit (button)

i have one button when i click that button i have to display dropdownlist1,textbox1 and textbo2,textbox3 values to gridview

for that how to do using c#

What I have tried:

  My design as follows


   Leave Type      dropdownlist1
   From Date        textbox1
   To Date          textbox2
   Reason           textbox3

     Submit (button)

i have one button when i click that button i  have to display dropdownlist1,textbox1 and textbo2,textbox3 values to gridview

for that how to do using c#
Posted
Updated 23-Jan-18 3:28am
Comments
F-ES Sitecore 23-Jan-18 6:43am    
A gridview is a bad choice to do this with, a gridview is for showing a collection of the same data type in a table, and that's not what you have. Use standard html+asp components to show this in a table\grid or write a custom control to do it.

1 solution

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebInterface.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click"/>

        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    </div>
    </form>
</body>
</html>











using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebInterface
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DropDownList1.Items.Add("MEDICAL");
            TextBox1.Text = "1Jan2000";
            TextBox2.Text = "2Jan2000";
            TextBox3.Text = "FEVER";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ConcurrentDictionary<string, Leave> MyDictionary = new ConcurrentDictionary<string, Leave>();
            Leave l = new Leave();
           
            l.LeaveType = DropDownList1.SelectedValue.Trim();
            l.FromDate = TextBox1.Text.Trim();
            l.ToDate = TextBox2.Text.Trim();
            l.Reason = TextBox3.Text.Trim();
            MyDictionary.TryAdd(l.FromDate,l);
            GridView1.DataSource = MyDictionary.Select(m => new { m.Value.LeaveType,m.Value.FromDate,m.Value.ToDate,m.Value.Reason });
            GridView1.DataBind();



        }

        public class Leave
        {
            public string LeaveType;
            public string FromDate;
            public string ToDate;
            public string Reason;
        }
    }
}
 
Share this answer
 
Comments
Laxmidhar tatwa technologies 23-Jan-18 21:28pm    
a good description
Shashank Laxman 24-Jan-18 8:55am    
Thanks

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