I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component public class AllViewComponent : ViewComponent { private readonly UserManager<ApplicationUser> _userManager; public AllViewComponent(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IViewComponentResult> InvokeAsync() { List<StudentViewModel> allUsers = new List<StudentViewModel>(); var items = await _userManager.Users.ToListAsync(); foreach (var item in items) { allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email }); }
According to our previous article how to use query string in asp.net, we use query string parameter for searching value from the database.Now, If you want to pass parameter value with special character like "&" . Let's take an simple example, how to pass & in QueryString parameter.
Here, In above mentioned code your username contains & symbol between you&me and we use & for separates the field.
Here, we use %26, in the place of & symbol. Any browser consider & symbol as %26.
<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
Default2.aspx.cs code
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default3.aspx?userName=" + Server.UrlEncode("you&me") + "&Password=jacob");
}
Now, your button click event call another webform, where you bind gridview through QueryString
Default3.aspx code
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="sno" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="sno" HeaderText="sno" InsertVisible="False"
ReadOnly="True" SortExpression="sno" />
<asp:BoundField DataField="userName" HeaderText="userName"
SortExpression="userName" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [user] WHERE (([userName] = @userName) AND ([Password] = @Password))">
<SelectParameters>
<asp:QueryStringParameter Name="userName" QueryStringField="userName"
Type="String" />
<asp:QueryStringParameter Name="Password" QueryStringField="Password"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
I-method
Response.Redirect("~/Default3.aspx?userName=" + Server.UrlEncode("you&me") + "&Password=jacob");Here, In above mentioned code your username contains & symbol between you&me and we use & for separates the field.
II-method
~/Default3.aspx?userName=you%26me&password=jacobHere, we use %26, in the place of & symbol. Any browser consider & symbol as %26.
Complete Code
Default2.aspx code<asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">LinkButton</asp:LinkButton>
Default2.aspx.cs code
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default3.aspx?userName=" + Server.UrlEncode("you&me") + "&Password=jacob");
}
Now, your button click event call another webform, where you bind gridview through QueryString
Default3.aspx code
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="sno" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="sno" HeaderText="sno" InsertVisible="False"
ReadOnly="True" SortExpression="sno" />
<asp:BoundField DataField="userName" HeaderText="userName"
SortExpression="userName" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [user] WHERE (([userName] = @userName) AND ([Password] = @Password))">
<SelectParameters>
<asp:QueryStringParameter Name="userName" QueryStringField="userName"
Type="String" />
<asp:QueryStringParameter Name="Password" QueryStringField="Password"
Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</div>
</form>
Comments
Post a Comment