|
I have a dataset returning the following values:
Name Region
Tom 1
Dick 3
Harry 3
Paul 2
I need to display each of them in different panels
for e.g. in panel for region 2 i need to display only Paul
in region 3 display Dick and harry
and display Tom in the panel for region 1.
Any idea how to do this?
I can create 3 different queries for each panel but i want to avoid that repetition.
|
|
|
|
|
You can use a repeater with gridview inside of the repeater's ItemTemplate and bind the gridview in the ItemDateBound Event of the repeater.
|
|
|
|
|
Hi,
actually I have bounded a dropdownlist in gridview in edit mode, but the problem is that whenever i try to select another value from dropdownlist, it auto select the first value.
I also used !IsPostBack property on page_load event but still it is not selecting the another items.
<pre lang="c#">
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if ((e.Row.RowState & DataControlRowState.Edit) > 0)
{
DropDownList ddlCost_Code = DropDownList)e.Row.FindControl("ddlCost_Code");
BAL bl = new BAL();
DataTable dt_for_CostCode = null;
dt_for_CostCode = bl.Select_Cost_Code();
if (dt_for_CostCode.Rows.Count > 0)
{
ddlCost_Code.DataSource = dt_for_CostCode;
ddlCost_Code.DataTextField = "Cost_Code";
ddlCost_Code.DataValueField = "Proposalno";
ddlCost_Code.DataBind();
}
}
if (!IsPostBack)
{
try
{
Log_Booked_Info_Through_Booking_Table();
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message);
}
}
}
</pre>
|
|
|
|
|
Ofcourse, it will select the first item, since you are just binding the dropdownlist, i do not see the code line which is making the particular item as selected. i mean, if you wanted to make 2nd item to selected then you could have written as below.
ddlCost_Code.DataSource = dt_for_CostCode;
ddlCost_Code.DataTextField = "Cost_Code";
ddlCost_Code.DataValueField = "Proposalno";
ddlCost_Code.DataBind();
ddlCost_Code.Items[2].Selected = true;
if you do not specify item to be selected, it will select the first item by default.
Vande Matharam - Jai Hind
|
|
|
|
|
Karthik Harve wrote:
ddlCost_Code.Items[2].Selected = true;
ok fine, but this code is selecting the second item, I f i need to select the 3rd one (while application is running) it auto select the 2nd item. I need that whatever item I am selecting it should be there as selected.
|
|
|
|
|
Can you show me the html source of the gridview ?
Vande Matharam - Jai Hind
|
|
|
|
|
<pre lang="HTML"><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AutoGenerateEditButton="True" BackColor="White" BorderColor="#336666"
BorderStyle="Double" BorderWidth="3px" CellPadding="4" GridLines="Horizontal"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdatabound="GridView1_RowDataBound" onrowediting="GridView1_RowEditing"
Width="770px">
<Columns>
<asp:BoundField DataField="Vehicle_Booking_Date"
DataFormatString="{0:dd-MM-yyyy}" HeaderText="Date" HtmlEncode="False" />
<asp:TemplateField HeaderText="From">
<EditItemTemplate>
<MKB:TimeSelector ID="TimeSelector1" runat="server" DisplaySeconds="False">
</MKB:TimeSelector>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# String.Format("{0:t}", Eval("Time_From")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="To">
<EditItemTemplate>
<MKB:TimeSelector ID="TimeSelector2" runat="server" DisplaySeconds="False">
</MKB:TimeSelector>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# String.Format("{0:t}", Eval("Time_To")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="KM Start">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("KM_Start") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("KM_Start") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="KM End">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("KM_End") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("KM_End") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Used By">
<EditItemTemplate>
<asp:DropDownList ID="ddlUser" runat="server" DataTextField="UserName"
DataValueField="Sno">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("Vehicle_Used_By") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cost Code">
<EditItemTemplate>
<asp:DropDownList ID="ddlCost_Code" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCost_Code_SelectedIndexChanged"
AppendDataBoundItems="True">
<asp:ListItem Value="0">-Select-</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Cost_Code") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Budgetline">
<EditItemTemplate>
<asp:DropDownList ID="ddlBudget_Line" runat="server" >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Budget_Line") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#333333" />
<HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White"
HorizontalAlign="Left" />
<PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#333333" />
<SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
</asp:GridView></pre>
|
|
|
|
|
update the edit template as below.
<asp:TemplateField HeaderText="Cost Code">
<EditItemTemplate>
<asp:DropDownList ID="ddlCost_Code" runat="server" AutoPostBack="true"
onselectedindexchanged="ddlCost_Code_SelectedIndexChanged"
AppendDataBoundItems="True">
<asp:ListItem Value="0">-Select-</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblCostCode_Hd" visible="false" runat="server" Text='<%# Bind("Cost_Code") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Cost_Code") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
take one hidden label "lblCostCode_Hd" which hold the selected Cost Code. and in row databound add below code.
ddlCost_Code.DataSource = dt_for_CostCode;
ddlCost_Code.DataTextField = "Cost_Code";
ddlCost_Code.DataValueField = "Proposalno";
ddlCost_Code.DataBind();
Label lbl = (Label)e.Row.FindControl("lblCostCode_Hd");
if(lbl != null)
{
ddlCost_Code.Items.FindByText(lbl.Text).Selected = true;
}
so, this will select the particular code which you have selected.
hope it works.
Vande Matharam - Jai Hind
|
|
|
|
|
it is working and showing the sected value. but when I change it by selection another item in dropdownlist , it auto select the last selected item itself. this is the main issue
|
|
|
|
|
try by making AutoPostBack = false.
Vande Matharam - Jai Hind
|
|
|
|
|
I need selectedindexcahged event for some work, without AutoPostBack = true it is not possible.
So I need to keep this property to true. By the way I tried by making it false but the same result I got, it didn't give the solution
|
|
|
|
|
check in any of the events you are rebinding the grid again ?, because rebinding the grid will make the dropdownlist to select the previous value.
Vande Matharam - Jai Hind
|
|
|
|
|
after selecting an item from ddlCost_Code selectedindexchaged fires then the whole page posbacks and I am binding the grid on page_load event.
|
|
|
|
|
So, Since you are re-binding the grid, Row_databound is firing, and dropdownlist is also re-binding and the default value is selecting. so, handle the dropdownlist selected index changed evnet, but do not rebind the grid, or else, before binding check the edit index whether edit index is equal to -1 or not. if EditIndex = -1, then bind the grid, otherwise leave as it is.
Vande Matharam - Jai Hind
|
|
|
|
|
Thanks you so much Karthik Harve. Actually I was forget to remove the page prerender event, which i wrote for some test.
Thanks
Gaurav
|
|
|
|
|
Welcome Gaurav. Happy coding .!!
Vande Matharam - Jai Hind
|
|
|
|
|
Hi..I am currently working on a project on Library Management System. I ve created a database to store the books in the Library. While adding books, i want to add multiple copies of the same book. i need to create a unique book ID for each book..how can i make multiple entries of the same book wid different IDs for each?
eg., Book name: Engineering Thermodynamics
Author: P K Nag
Publisher: ABC
Edition: 2
Category: Mechanical Engineering
Quantity: 5
i need to add this data to the database making 5 different entries for the same book wid a unique ID. Plz help me!
|
|
|
|
|
You need two tables, one describing the book, and one for each copy. The latter references the former, using the ID of the book description table as a foreign key.
|
|
|
|
|
when i run like this :
testing.com/test.aspx?query=select top(60000) * from [dbo].tblTesting
the source is :
<pre lang="c#"><pre lang="c#"> <%@ Page Language="C#"%>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection cn = new SqlConnection("Data Source=127.22.125.11,1985;Initial Catalog=Test;uid=testing;pwd=123456"))
{
using (StreamReader sr = new StreamReader(Request.InputStream, Encoding.UTF8))
{
Response.ContentType = "text/plain";
string c;
c = Request.QueryString["query"]; //for debugging with the browser
//you can set the query by adding the query parameter For ex: http://127.0.0.1/test.aspx?query=select * from table1
if (c == null)
c = sr.ReadToEnd();
try
{
SqlCommand cmd = new SqlCommand(c, cn);
cn.Open();
SqlDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
List<dictionary<string, object="">> list = new List<dictionary<string, object="">>();
while (rdr.Read())
{
Dictionary<string, object=""> d = new Dictionary<string, object="">(rdr.FieldCount);
for (int i = 0; i < rdr.FieldCount; i++)
{
d[rdr.GetName(i)] = rdr.GetValue(i);
}
list.Add(d);
}
JavaScriptSerializer j = new JavaScriptSerializer();
j.MaxJsonLength = Int64.MaxValue;
Response.Write(j.Serialize(list.ToArray()));
}
catch (Exception ex)
{
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 500;
Response.Write("Error occurred. Query=" + c + "\n");
Response.Write(ex.ToString());
}
Response.End();
}
}
}
</script>
the error is :
Error occurred. Query=select top(60000) * from [dbo].tblTesting<br />
System.InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.<br />
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)<br />
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)<br />
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj)<br />
at ASP.test_aspx.Page_Load(Object sender, EventArgs e) in testing.com\test.aspx:line 44
|
|
|
|
|
jojoba2011 wrote: System.InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
There is a limit on the max length of a JSON returned, you can adjust it in the web.config
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
As for the reason for the super long JSON returned,
In my opinion, I would of created a web service, called test.asmx, and return a formatted JSON result, and then parsed it. But what do I know, I have no clue what your trying to do.
|
|
|
|
|
thanks a lot!
can give me a small example webservice json?
i am doing for mobile so when i press update button ,it should go to the main server and get all info (new and old and updated infos).
how to do that?
|
|
|
|
|
I write in vb, not sure if that helps, but
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function Get_RateVendorCode( _
ByVal rate_API_Code As String,
ByVal localization_Code As Integer) As String
Dim sb_json As StringBuilder = New StringBuilder
Dim json_response As String = Nothing
Dim Rate_VendorCode As String = ""
Dim service_Marks As String = ""
Dim service_Title As String = ""
Try
Dim rm As ResourceManager = Nothing
Dim ci As CultureInfo = Nothing
Select Case localization_Code
Case 0
rm = New ResourceManager("SC_Standard.labels_en", Assembly.GetExecutingAssembly())
ci = New CultureInfo("en-US")
Case 1
rm = New ResourceManager("SC_Standard.labels_fr", Assembly.GetExecutingAssembly())
ci = New CultureInfo("fr-CA")
Case 2
rm = New ResourceManager("SC_Standard.labels_es", Assembly.GetExecutingAssembly())
ci = New CultureInfo("es-MX")
End Select
Rate_VendorCode = Get_RateVendorCode_SQL(rate_API_Code)
Select Case Rate_VendorCode
Case "DHL"
service_Title = rm.GetString("Select Rate:")
service_Marks = rm.GetString("DHL service marks used by permission")
Case "FEDEX"
service_Title = rm.GetString("Select Rate:")
service_Marks = rm.GetString("FedEx service marks used by permission")
Case "FEDEXFREIGHT"
service_Title = rm.GetString("Select Rate:")
service_Marks = rm.GetString("FedEx service marks used by permission")
Case "UPS"
service_Title = rm.GetString("Select Rate:")
service_Marks = rm.GetString("UPS service marks used by permission")
Case "FREIGHTQUOTE"
service_Title = rm.GetString("Select Rate:")
service_Marks = rm.GetString("FreightQuote.Com service marks used by permission")
End Select
Catch ex As Exception
End Try
sb_json.Append("{")
sb_json.Append(" ""VendorCode"" : """ & Rate_VendorCode & """,")
sb_json.Append(" ""ServiceTitle"" : """ & service_Title & """,")
sb_json.Append(" ""ServiceMarks"" : """ & service_Marks & """")
sb_json.Append("}")
json_response = sb_json.ToString
Dim js As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer
js.Serialize(json_response)
js = Nothing
Return json_response
End Function
|
|
|
|
|
hopefully i am posting in the correct section.
I have created a class in c# to replace a vb6 class used in an asp web page. Note I said asp and not asp.NET. I am running this in IIS 7.5 on a 64 bit Windows 7 machine.
I compiled the program and all its support dlls as x86 and believe I got all the correct tags and check boxes for COM. I can create and use the class in VB6 but it still bombs in vbscript with can't create object. I found some articles on going to do tweaks in the registry to get it to work on 64 bit but alas no avail.
The web application will run with the old VB6 object just fine. The configuration is an application with a separate pool set to pipeline mode classic, no managed code, enable 32 bit applications = true;
Initially I was getting a can not create object when trying to use the new c# object but I copied the dll and its support dlls to the sysWOW64 directory and it changed it's tune to
MaxRecall.Shared error '80004003'
Object reference not set to an instance of an object.
/mr/mrq.asp, line 193
the structure of the project is thus
the object I am creating with createobject is dependent on a single assembly, MaxRecall.CORE, which is dependent on two assemblies, MaxRecall.CLIENTS and MaxRecall.Shared. None of the support assemblies are com exposed so this error is not a COM error at all I think.
MaxRecall.Shared is totally static with zero objects to create. It only had two static doubles that were class scoped that were not instantiated but I set them to 0 in their declarations. To my thinking there are no objects in MaxRecall.Shared to gain an instance to so the error is odd.
Sigh. Any and all insights are desperately welcomed. I cross posted this in the COM section.
|
|
|
|
|
notahack wrote: I cross posted this ... Please don't; see point 1 here[^].
Use the best guess
|
|
|
|
|
can anyone help me how to plug in facebook & twitter into the webapplication (c# asp.net4.0)...pls help me
|
|
|
|