Click here to Skip to main content
15,884,629 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Asp.net 4.0 Pin
Not Active21-Dec-11 9:51
mentorNot Active21-Dec-11 9:51 
GeneralRe: Asp.net 4.0 Pin
netJP12L21-Dec-11 10:36
netJP12L21-Dec-11 10:36 
GeneralRe: Asp.net 4.0 Pin
Not Active21-Dec-11 12:26
mentorNot Active21-Dec-11 12:26 
QuestionBulk Insert into database from datatable or dataset or datagrid Pin
yesu prakash21-Dec-11 3:37
yesu prakash21-Dec-11 3:37 
AnswerRe: Bulk Insert into database from datatable or dataset or datagrid Pin
rkrishnach22-Dec-11 1:12
rkrishnach22-Dec-11 1:12 
QuestionBulk Insert into database Pin
yesu prakash21-Dec-11 3:37
yesu prakash21-Dec-11 3:37 
AnswerRe: Bulk Insert into database Pin
R. Giskard Reventlov21-Dec-11 7:21
R. Giskard Reventlov21-Dec-11 7:21 
QuestionGridview rendering Issue Pin
Rameez Raja21-Dec-11 0:05
Rameez Raja21-Dec-11 0:05 
Hi all i have binded data with gridview in presention point view it is working but while inserting the data to DB and iam traversing the girdview iam getting the index missing . please guide me where iam doing wrong

DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("StudentID", Type.GetType("System.String")));
dataTable.Columns.Add(new DataColumn("StudentName", Type.GetType"System.String")));
dataTable.Columns.Add(new DataColumn("MajorName", Type.GetType("System.String")));
dataTable.Columns.Add(new DataColumn("StudenMarks", Type.GetType("System.Int16")));

dataTable.Rows.Add(new string[] { "1","Student1","English"});
dataTable.Rows.Add(new string[] {"2", "Student2","English"});
dataTable.Rows.Add(new string[] { "3","Student3","Hindi"});
dataTable.Rows.Add(new string[] { "4", "Student4","Hindi"});

dataTable.Rows.Add(new string[] { "5", "Student4","Hindi"});
GridView1.DataSource = dataTable;
GridView1.DataBind();



AND my gridview looks like the below
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" onrowdatabound="GridView1_RowDataBound"
="" ondatabound="GridView1_DataBound">
<columns>
<asp:boundfield datafield="StudentID" headertext="Student ID">
<asp:boundfield datafield="StudentName" headertext="Student Name">
<asp:templatefield headertext="Major Name">
<itemtemplate>
<asp:label id="lblTypeName" runat="server" text="<%# Eval("MajorName") %>">


<asp:templatefield headertext="Marks">
<itemtemplate>
<asp:textbox id="txtMarks" runat="server" class="calculate" onkeyup="calculate()"
="" width="95%">


<asp:templatefield headertext="Sub-Total">
<itemtemplate>
<asp:label id="lblSubTotal" runat="server" class="SubTotal">







And on Row Data bound event i have the below code
string tmpCategoryName = string.empty;

protected void GridView1_RowDataBound (object sender, GridViewRowEventArgs e)
{
// If the current row is a DataRow (and not a Header or Footer row), then do stuff.
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drv = (DataRowView)e.Row.DataItem;
if (tmpCategoryName != drv["MajorName"].ToString())
{
tmpCategoryName = drv["MajorName"].ToString();
// Get a reference to the current row's Parent, which is the Gridview (which happens to be a table)
//Table tbl = e.Row.Parent as Table;
Table tbl = e.Row.Parent as Table;
if (tbl != null)
{
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
TableCell cell = new TableCell();
// Span the row across all of the columns in the Gridview
cell.ColumnSpan = this.grdProduction.Columns.Count;
cell.Width = Unit.Percentage(100);
cell.Style.Add("font-weight", "bold");
cell.Style.Add("text-align", "center");
HtmlGenericControl span = new HtmlGenericControl("span");
span.InnerHtml = "(" + tmpCategoryName + ")";
cell.Controls.Add(span);
row.Cells.Add(cell);
tbl.Rows.AddAt(tbl.Rows.Count - 1, row);
}
}
} }



OUTPUT while getting the data from Gridview

100 1 StudentName1
2
200 3 StudentName 2
300 4 StudentName 3
400 5 StudentName 4

but when iam going to insert the data from gridview to Database on button click iam getting the Invalid data index missing ( Invalid data entry as well)


Regards,
Questiondatagrid link button Pin
sheemap20-Dec-11 22:48
sheemap20-Dec-11 22:48 
AnswerRe: datagrid link button Pin
R. Giskard Reventlov20-Dec-11 22:56
R. Giskard Reventlov20-Dec-11 22:56 
AnswerRe: datagrid link button Pin
Karthik Harve20-Dec-11 22:56
professionalKarthik Harve20-Dec-11 22:56 
AnswerRe: datagrid link button Pin
uspatel21-Dec-11 0:20
professionaluspatel21-Dec-11 0:20 
Questionlink button Pin
sheemap20-Dec-11 20:47
sheemap20-Dec-11 20:47 
AnswerRe: link button Pin
srinivas vadepally20-Dec-11 22:13
srinivas vadepally20-Dec-11 22:13 
AnswerRe: link button Pin
Karthik Harve20-Dec-11 22:55
professionalKarthik Harve20-Dec-11 22:55 
Questionhow use visio activeX contorl in asp.net Pin
Suhail Ali20-Dec-11 2:11
Suhail Ali20-Dec-11 2:11 
AnswerRe: how use visio activeX contorl in asp.net Pin
thatraja20-Dec-11 4:56
professionalthatraja20-Dec-11 4:56 
QuestionSecurity Pin
David C# Hobbyist.19-Dec-11 10:54
professionalDavid C# Hobbyist.19-Dec-11 10:54 
AnswerRe: Security Pin
thatraja19-Dec-11 17:35
professionalthatraja19-Dec-11 17:35 
SuggestionRe: Security Pin
mojoc20-Dec-11 7:57
mojoc20-Dec-11 7:57 
AnswerRe: Security Pin
jkirkerx20-Dec-11 17:21
professionaljkirkerx20-Dec-11 17:21 
GeneralRe: Security Pin
David C# Hobbyist.21-Dec-11 11:13
professionalDavid C# Hobbyist.21-Dec-11 11:13 
GeneralRe: Security Pin
jkirkerx21-Dec-11 11:55
professionaljkirkerx21-Dec-11 11:55 
GeneralRe: Security Pin
David C# Hobbyist.21-Dec-11 14:06
professionalDavid C# Hobbyist.21-Dec-11 14:06 
GeneralRe: Security Pin
jkirkerx21-Dec-11 15:25
professionaljkirkerx21-Dec-11 15:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.